Select sheet

  • Thread starter Thread starter Abdul
  • Start date Start date
A

Abdul

Hi,

I am selecting varous sheets thru a userform combobox
based combobox value. How can I store the sheet name
before loading the userform and return to that sheet when
I close the user form with a close button?

Thanks in advance

Abdul
 
Abdul,

Try something like

Sub SaveLocation(Optional GoBack As Variant = False)
Static TopLeftCell As Range
Static SelectedCells As Range
If GoBack = False Then
Set TopLeftCell = ActiveWindow.VisibleRange(1, 1)
Set SelectedCells = Selection
Else
Application.Goto TopLeftCell
SelectedCells.Select
End If
End Sub

To save the current location, use

SaveLocation

Then, to return to the location, use
SaveLocation GoBack:=True
 
Back
Top