PDA

View Full Version : Run sub when sheet is activated



gimli
11-23-2011, 09:18 AM
Hi all,

Noob question..im would like this sub to run everytime someone clicks on the work sheet tab. I have this code on the object for the sheet. Or any other ideas would be great.

thanks

Option Explicit
Sub HideRowsIfSumZero()
Dim cell As Range
Application.ScreenUpdating = False
For Each cell In Range("C2.C7:C100")
If UCase(cell.Value) = "0" Then
cell.EntireRow.Hidden = True
End If
Next
Application.ScreenUpdating = True
End Sub

monarchd
11-23-2011, 09:36 AM
Click the sheet where you want this to happen. Then, from the dropdowns at the top, choose Worksheet, then Activate.

Here's my test code:



Private Sub Worksheet_Activate()
MsgBox "Cool.", vbExclamation, "I am working"
End Sub

Aflatoon
11-23-2011, 09:36 AM
I believe that this will do:
Private Sub Worksheet_Activate()
HideRowsIfSumZero
End Sub