+ Reply to Thread
Results 1 to 5 of 5

Running a Marcro when sheet is opened

  1. #1
    Mark Dullingham
    Guest

    Running a Marcro when sheet is opened

    I recorde a simple macro to hide all the blank cells in a sheet and pasted
    into the code of a command button as follws:

    Private Sub CommandButton1_Click()
    Range("B6:K425").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=1, Criteria1:="<>"
    End Sub

    What I would like to do is have this macro apply when the sheet is opened
    but I don't know what to enter after the 'Private Sub' bit instead of
    CommandButton1_Click().

    Can anyone help please.

    Thanks a plenty in advance.


  2. #2
    Jason Zischke
    Guest

    RE: Running a Marcro when sheet is opened

    Try This :

    Private Sub Worksheet_Activate()

    Jason Zischke

    "Mark Dullingham" wrote:

    > I recorde a simple macro to hide all the blank cells in a sheet and pasted
    > into the code of a command button as follws:
    >
    > Private Sub CommandButton1_Click()
    > Range("B6:K425").Select
    > Selection.AutoFilter
    > Selection.AutoFilter Field:=1, Criteria1:="<>"
    > End Sub
    >
    > What I would like to do is have this macro apply when the sheet is opened
    > but I don't know what to enter after the 'Private Sub' bit instead of
    > CommandButton1_Click().
    >
    > Can anyone help please.
    >
    > Thanks a plenty in advance.
    >


  3. #3
    Mark Dullingham
    Guest

    RE: Running a Marcro when sheet is opened

    Thanks for the quick response Jason.
    Tried your suggestion but it didn't work!
    Do I have to save or shut the workbook first?

    "Jason Zischke" wrote:

    > Try This :
    >
    > Private Sub Worksheet_Activate()
    >
    > Jason Zischke
    >
    > "Mark Dullingham" wrote:
    >
    > > I recorde a simple macro to hide all the blank cells in a sheet and pasted
    > > into the code of a command button as follws:
    > >
    > > Private Sub CommandButton1_Click()
    > > Range("B6:K425").Select
    > > Selection.AutoFilter
    > > Selection.AutoFilter Field:=1, Criteria1:="<>"
    > > End Sub
    > >
    > > What I would like to do is have this macro apply when the sheet is opened
    > > but I don't know what to enter after the 'Private Sub' bit instead of
    > > CommandButton1_Click().
    > >
    > > Can anyone help please.
    > >
    > > Thanks a plenty in advance.
    > >


  4. #4
    Jason Zischke
    Guest

    RE: Running a Marcro when sheet is opened

    Mark Dullingham,

    Yes you can the sub should run you open your workbook and that sheet is
    active or when you switch between another sheet and back to the sheet that
    has that sub in it.

    Jason Zischke

    "Mark Dullingham" wrote:

    > Thanks for the quick response Jason.
    > Tried your suggestion but it didn't work!
    > Do I have to save or shut the workbook first?
    >
    > "Jason Zischke" wrote:
    >
    > > Try This :
    > >
    > > Private Sub Worksheet_Activate()
    > >
    > > Jason Zischke
    > >
    > > "Mark Dullingham" wrote:
    > >
    > > > I recorde a simple macro to hide all the blank cells in a sheet and pasted
    > > > into the code of a command button as follws:
    > > >
    > > > Private Sub CommandButton1_Click()
    > > > Range("B6:K425").Select
    > > > Selection.AutoFilter
    > > > Selection.AutoFilter Field:=1, Criteria1:="<>"
    > > > End Sub
    > > >
    > > > What I would like to do is have this macro apply when the sheet is opened
    > > > but I don't know what to enter after the 'Private Sub' bit instead of
    > > > CommandButton1_Click().
    > > >
    > > > Can anyone help please.
    > > >
    > > > Thanks a plenty in advance.
    > > >


  5. #5
    Mark Dullingham
    Guest

    RE: Running a Marcro when sheet is opened

    Removed some code that was attached to another command button that reversed
    the filter and all is chipper now.
    thanks for taking the time

    "Jason Zischke" wrote:

    > Mark Dullingham,
    >
    > Yes you can the sub should run you open your workbook and that sheet is
    > active or when you switch between another sheet and back to the sheet that
    > has that sub in it.
    >
    > Jason Zischke
    >
    > "Mark Dullingham" wrote:
    >
    > > Thanks for the quick response Jason.
    > > Tried your suggestion but it didn't work!
    > > Do I have to save or shut the workbook first?
    > >
    > > "Jason Zischke" wrote:
    > >
    > > > Try This :
    > > >
    > > > Private Sub Worksheet_Activate()
    > > >
    > > > Jason Zischke
    > > >
    > > > "Mark Dullingham" wrote:
    > > >
    > > > > I recorde a simple macro to hide all the blank cells in a sheet and pasted
    > > > > into the code of a command button as follws:
    > > > >
    > > > > Private Sub CommandButton1_Click()
    > > > > Range("B6:K425").Select
    > > > > Selection.AutoFilter
    > > > > Selection.AutoFilter Field:=1, Criteria1:="<>"
    > > > > End Sub
    > > > >
    > > > > What I would like to do is have this macro apply when the sheet is opened
    > > > > but I don't know what to enter after the 'Private Sub' bit instead of
    > > > > CommandButton1_Click().
    > > > >
    > > > > Can anyone help please.
    > > > >
    > > > > Thanks a plenty in advance.
    > > > >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1