VBA for last active worksheet

johannes2008

New Member
Joined
Aug 20, 2010
Messages
45
Office Version
  1. 365
Platform
  1. Windows
Hello All

I am wondering if anyone knows the code that I can put in a button that will take me back to the last active worksheet, not necessarily the previous worksheet in the worksheet order. My sheets all have names with spaces.

Thanks
-Johannes
 
Hello clever peeps.

I appreciate this thread is very old now, but I was just wondering why this code isn't working for me (Joe4, not ZVI as unfortunately this doesn't work at all for me and disables all the other macro buttons I have!). I have the codes in the correct place (at least I think I do! Where is the 'Public Variable' code put (I put it in 'ThisWorkbook' and then in every sheet)), assigned the macro to a button, switched sheets (both via macro buttons and tabs), but keep getting the message, "You have not switched sheets yet since opening the file!"

Any guidance would be gratefully received!
Sorry, I never saw this, as I wasn't subscribed anymore to the thread.

So, you should put the Worlbook_SheetDeactivate procedure in the "ThisWorkbook" module.
Then the Public variable declaration and other procedure should go in a new, standard module (insert a new module and enter that code there).
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top