+ Reply to Thread
Results 1 to 9 of 9

After macro completes, there is no active cell

  1. #1
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,272

    After macro completes, there is no active cell

    I didn't even think it was possible to have a state where there is no active cell.

    Attached is a sample file. There is a spin button at the top. The purpose of the spin button is to move the selected item up or down. (details below)

    The spin button works, but after the code completes, there is no cell selected/active on the worksheet, even though the macro explicitly activates a cell. The address box is blank. If I step through the code in debug mode, it works as expected, with a selection border around the desired cell and its address in the address box.

    Select any item in column B. The spin button will become enabled. Click the Up arrow to move the item up in the list, and the Down arrow to move it down.

    How do I get it to leave a cell selected, as it does when I step through the code?
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,046

    Re: After macro completes, there is no active cell

    I get an error when the code is trying to enable the spin button after changing selection. "Method or data member not found", even though the SpinButton is clearly there and clearly named as per the code.
    Even tried deleting your SB and adding a new one with the same name, same result.

    However, if I add icons and link them to the Move Up / Move Down code, it all works seamlessly so I don't even get to see the state with no active cell.

    I very much doubt that's helpful, but thought I'd report it back anyway.

    BSB

  3. #3
    Forum Contributor
    Join Date
    02-12-2024
    Location
    Australia
    MS-Off Ver
    365
    Posts
    187

    Re: After macro completes, there is no active cell

    I get your symptoms for EVERY ALTERNATE spin button press (it works as expected/desired every other time).

    If I put a one second delay in, it works as desired every time. So I think some sort of timing issue?
    (Sorry haven't had time to investigate further)

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,072

    Re: After macro completes, there is no active cell

    Can only be a focus issue...Spin Button takes the focus away from the sheet...
    Add a shape to sheet and see...
    Please Login or Register  to view this content.
    This solves...

    I tried DoEvents and Activating the sheet too...This is not stable enough though...works only sometimes...
    Perhaps better to make use of Forms Control in this case...
    Last edited by Sintek; 07-01-2025 at 05:12 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: After macro completes, there is no active cell

    You could probably get away with toggling the visibility of the control

    Please Login or Register  to view this content.
    but yeah, better not to be using activex.
    Everyone who confuses correlation and causation ends up dead.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,272

    Re: After macro completes, there is no active cell

    Quote Originally Posted by Sintek View Post
    Can only be a focus issue...Spin Button takes the focus away from the sheet...
    I think you are onto something there. I was going to change the "TakeFocusOnClick" property, but spin buttons don't have that (command buttons do).

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,272

    Re: After macro completes, there is no active cell

    Quote Originally Posted by romperstomper View Post
    better not to be using activex.
    <sigh> I hate coding for forms controls, not even sure how to trap a click event. But I'll look into that.

  8. #8
    Registered User
    Join Date
    02-02-2022
    Location
    Sydney, Australia
    MS-Off Ver
    MS 365
    Posts
    18

    Re: After macro completes, there is no active cell

    Adding the Me.SpinButtonMoveItem.Select before Cell Activate line seems to fix it.

    Please Login or Register  to view this content.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,272

    Re: After macro completes, there is no active cell

    Quote Originally Posted by Alex Blakenburg View Post
    Adding the Me.SpinButtonMoveItem.Select before Cell Activate line seems to fix it.
    It sure does. And who the hƏll knows why.

    This whole behavior is perplexing. As I mentioned earlier, I didn't even think it was possible for Excel to be in a state where no cell was active. But this fixes it in my file.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Pause macro while external data request completes
    By sungen99 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-28-2017, 05:55 PM
  2. Macro completes 1st step not 2nd. Also run time error
    By Chaty in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2017, 12:22 PM
  3. [SOLVED] Windows Sounds when macro completes?
    By majime01 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-29-2015, 04:47 PM
  4. [SOLVED] Return to starting cell after macro completes
    By jen1220 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2014, 05:44 PM
  5. [SOLVED] Runtime Error 9, open debug and macro completes
    By Aaron092 in forum Excel Programming / VBA / Macros
    Replies: 42
    Last Post: 11-03-2014, 10:09 AM
  6. Save VBA errors & report them after macro completes
    By Philb1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2013, 01:00 AM
  7. Pausing macro until .xla function completes
    By rtylerdunn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2007, 05:57 PM

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