Activate Current Worksheet in Excel

Anonymous
2023-09-08T17:05:13+00:00

Hi,

I have a macro for a sheet called as BEF , macro will run and interact with other worskheets also during macro execution . At the end of the macro execution, Another worksheet is activated always., How to ensure that always BEF is activated here,

Please do not tell me that use Wroksheets("BEF").Activate here as my BEF name is not same , it can take 4 diff names dpeneding on selection by user at the start of opening excel.

How to activate current sheet using VBA?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points MVP Volunteer Moderator
    2023-09-21T14:58:13+00:00

    How can the user click on a button on a sheet if that sheet is not the active sheet?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-09-21T09:47:53+00:00

    Dear Sir,

    Your code works just fine for all cases, but I am facing an issue here.

    IF we do not click on the worksheet, and just press button, then above code will not understand.

    How to activate the sheet when user has just put the cursor on that sheet at the last event and not even click on any cell in that particular worksheet?

    Hoep you got my requirement .

    Right now, logic remembers last active sheet as last cell clicked worksheet here , but i want it to remember last mouse cursor worksheet and activate that aprticulae sheet also

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points MVP Volunteer Moderator
    2023-09-18T06:33:45+00:00

    That depends on your CPU and on how many other processes are using CPU capacity.

    In a quick test on my PC, activating a worksheet took about 0.5 ms = 500 µs

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-09-17T14:56:07+00:00

    It will consume how much ina macro typically like microseconds?

    Was this answer helpful?

    0 comments No comments
  5. HansV 462.6K Reputation points MVP Volunteer Moderator
    2023-09-08T18:22:06+00:00

    At the beginning of the macro:

        Dim wshCurrent As Worksheet
        Set wshCurrent = ActiveSheet
    

    At the end:

        wshCurrent.Activate
    

    Was this answer helpful?

    0 comments No comments