Consulting

Results 1 to 3 of 3

Thread: Run sub when sheet is activated

  1. #1

    Run sub when sheet is activated

    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

    [VBA]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
    [/VBA]

  2. #2
    VBAX Regular
    Joined
    Oct 2011
    Posts
    41
    Location
    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

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    I believe that this will do:
    [vba]Private Sub Worksheet_Activate()
    HideRowsIfSumZero
    End Sub[/vba]
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •