Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: A little nuisance I'd like to do away with. Can you help?

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hey everyone!
    I appreciate the great help in here!

    Here's an example of something I have put up with for a long time, but perhaps someone in here has dealt with the same problem.

    There are several examples but I'll give you the one I use the most.

    I have a Hide and Unhide macros which do the obvious for column headers, sheet tabs, ect, ect...

    Why does it seem neccesary that there has to be an active cell before this macros will run with no errors?

    If I run this Macro and several others have had the same problem, I recieve a Method of Range type error. It's not usually a huge deal, but sometimes I have not wanted to select any cell for one reason or another.
    When I do activate a cell with, activate or select, the macro runs fine...?

    This seems to be a problem whenever dealing with Excel objects. No other macros are dependant on this active cell thingamabob.

    I appreciate you reading my book and posting a reply.

    Tom



    [ This Message was edited by: TsTom on 2002-03-26 05:41 ]

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Leiden, The Netherlands
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I recognize the problem. Some VBA methods expect a cell to be selected in order to work. This is the case for the CurrentRegion method, and probably for a couple of other ones too. The problem occurs when a macro is activated by a command button. The button gets the focus when it is pressed, which deselects the active cell. I usually solve this problem by selecting a cell (e.g. "A1") in the CurrentSheet at the start of the macro.

    Marc

  3. #3
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Tom

    Marc has hit the nail on the head! If the CommandButton is from the Contol toolbox you can set It's TakeFocus******* Property to False as another fix.





  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks guys
    Am going to test it immediately.
    Take focus on click = Not
    Got It
    Tom

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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