ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Capturing the selected tab in a worksheet_deactivate macro (https://www.excelbanter.com/excel-programming/319563-capturing-selected-tab-worksheet_deactivate-macro.html)

jkitzy

Capturing the selected tab in a worksheet_deactivate macro
 
HELP! Here's what I need to do.

On deactivating a particular worksheet in a workbook, I need to run a
complex update macro (which I'm having no trouble with). Problem is this, to
accomplish updating all the pages, etc. in the deactivate macro, I have to
activate other sheets in the workbook. So, let's say, the deactivate macro is
on Sheet1, and I do a bunch of stuff on Sheet2 and Sheet 3 during the
deactivate macro, but I clicked on Sheet6, initiating the macro.

At the end of the deactivate macro, how do I get it to go back to Sheet6 (or
whatever sheet was selected?



KRCowen

Capturing the selected tab in a worksheet_deactivate macro
 
The following should help

Private Sub Worksheet_Deactivate()
Dim s As Worksheet
Set s = ActiveSheet
'do your stuff here
s.Activate
End Sub

If any of your complex updating involves selecting sheet1 (or the sheet which
triggers this deactivate code) you could have a loop problem. Otherwise this
should put you on the sheet you selected which triggered the deactivation of
the sheet.

Good luck.

Ken
Norfolk, Va

ps Merry Christmas


All times are GMT +1. The time now is 08:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com