+ Reply to Thread
Results 1 to 5 of 5

Selected cell doesn't stay selected

  1. #1
    Registered User
    Join Date
    08-16-2012
    Location
    Almere
    MS-Off Ver
    Excel 2003
    Posts
    48

    Selected cell doesn't stay selected

    I have a simple piece of VBA code that works great but.....
    after a while the code just stops working ???
    The idea is to keep Cell A1 selected, and when a user selects a different cell, the selected cell should return to A1 again
    Can anyone see what the problem should be ?
    The code is
    Please Login or Register  to view this content.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Selected cell doesn't stay selected

    Hello minifreak,

    It seems like you only want Cell A1 to be the Cell that can be accessed. Then try:

    Please Login or Register  to view this content.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,316

    Re: Selected cell doesn't stay selected

    It's a selection change event ... and you are selecting a cell in it. So, what do you think happens? And it's going to fire every time any cell on the sheet is fired. I suspect there might be a bit of a loop going on there.

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Selected cell doesn't stay selected

    @ TMSchucks,

    Hi TMS,

    But that is what the OP states:

    when a user selects a different cell, the selected cell should return to A1 again
    To me it would appear that only Cell A1 can or should be selected.

    In which case just
    Please Login or Register  to view this content.
    would suffice.
    Last edited by Winon; 10-25-2012 at 04:17 AM.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,316

    Re: Selected cell doesn't stay selected

    @Winon: but you can't select a cell, any cell, in a selection change event without disabling event handling.

    My understanding was not that the OP cannot select a cell other than A1 but that he cannot select a cell other than A1 if A1 is blank. Not sure of the value of the variant variable Q but, whatever.

    Try leaving cell A1 blank and selecting a cell other than A1; step through the code:

    Please Login or Register  to view this content.

    You'll see that it executes the code again (at least once). I think Excel/VBA is clever enough to notice this but you should still cater for it.

    At best, it slows down the code. At worst, it could crash.


    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1