Hello,
You just need to change a couple of lines. There's no need to activate each sheet as you can refer to it without activating it (plus the code will run quicker).
Sub ConditionalHide()
Dim cRange As String
cRange = Sheets(1).Range("A1")
For i = 2 To Sheets.Count
If Sheets(i).Range("A1").Value <> cRange Then
Sheets(i).Visible = False
Else: Sheets(i).Visible = True
End If
Next i
End Sub
HTH,
Dax.
Sure. The easiest way is to capture the worksheet (and Cell) that you are starting at.
In your code, before you do anything else declare a worksheet object and capture where you are at. Something like:
Dim wsCurrent as worksheet
set wsCurrent = activesheet
Then when you are done processing you check to see if you have changed location during the processing, either intentionally or unintentionally. Something like:
If Activesheet.Name <> wsCurrent.Name then
wsCurrent.Activate
End If
Now that you are back a your starting point, destroy the object variables. It's not absolutely necessary, just good coding practice.
' Recover the Memory
Set wsCurrent = Nothing
You should now be back where you started.
Tuc
Nice catch! I completely overlooked the activate method being called.
Perfect! Thanks for the help!