+ Reply to Thread
Results 1 to 6 of 6

If activesheet is called X, then do y

  1. #1
    Darin Kramer
    Guest

    If activesheet is called X, then do y


    Hi guys,

    I need some VBA that says if the active sheet is "dogs", then call macro
    entitled get dogs. If active sheet is "cats", then call macro entitled
    "get Cats".

    Possible...?

    Thanks!!

    D


    *** Sent via Developersdex http://www.developersdex.com ***

  2. #2
    Die_Another_Day
    Guest

    Re: If activesheet is called X, then do y

    Assuming everything exists..
    Run ActiveSheet.Name

    Charles
    xl Geek

    Darin Kramer wrote:
    > Hi guys,
    >
    > I need some VBA that says if the active sheet is "dogs", then call macro
    > entitled get dogs. If active sheet is "cats", then call macro entitled
    > "get Cats".
    >
    > Possible...?
    >
    > Thanks!!
    >
    > D
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***



  3. #3
    PCLIVE
    Guest

    Re: If activesheet is called X, then do y

    One way I think will work is:

    if activesheet.name = "dogs" then GetDogs
    if activesheet.name = "cats" then GetCats

    However, when is this code supposed to run. Is it based on anytime the
    sheet is active, or is it dependent on some other code that runs?
    If it is to run any time those sheets are activated then you could add code
    specifically to that sheet.
    For example:

    Right-click on sheet "dogs" and select View code. Click General dropdown
    and select Worksheet. Click other dropdown and make sure it is on
    Activate".
    Then in your code, enter the macro name you want to run when this sheet is
    selected. Here's what it would look like:

    Private Sub Worksheet_Activate()
    GetDogs
    End Sub


    HTH,
    Paul


    "Darin Kramer" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi guys,
    >
    > I need some VBA that says if the active sheet is "dogs", then call macro
    > entitled get dogs. If active sheet is "cats", then call macro entitled
    > "get Cats".
    >
    > Possible...?
    >
    > Thanks!!
    >
    > D
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  4. #4
    PCLIVE
    Guest

    Re: If activesheet is called X, then do y

    One way I think will work is:

    if activesheet.name = "dogs" then GetDogs
    if activesheet.name = "cats" then GetCats

    However, when is this code supposed to run. Is it based on anytime the
    sheet is active, or is it dependent on some other code that runs?
    If it is to run any time those sheets are activated then you could add code
    specifically to that sheet.
    For example:

    Right-click on sheet "dogs" and select View code. Click General dropdown
    and select Worksheet. Click other dropdown and make sure it is on
    Activate".
    Then in your code, enter the macro name you want to run when this sheet is
    selected. Here's what it would look like:

    Private Sub Worksheet_Activate()
    GetDogs
    End Sub


    HTH,
    Paul


    "Darin Kramer" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi guys,
    >
    > I need some VBA that says if the active sheet is "dogs", then call macro
    > entitled get dogs. If active sheet is "cats", then call macro entitled
    > "get Cats".
    >
    > Possible...?
    >
    > Thanks!!
    >
    > D
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  5. #5
    Die_Another_Day
    Guest

    Re: If activesheet is called X, then do y

    Oops I forgot the "get"
    Run "get" & Activesheet.Name
    I eliminated the space because I don't think excel will let you have a
    space in a macro name.

    Charles
    xl Geek
    Die_Another_Day wrote:
    > Assuming everything exists..
    > Run ActiveSheet.Name
    >
    > Charles
    > xl Geek
    >
    > Darin Kramer wrote:
    > > Hi guys,
    > >
    > > I need some VBA that says if the active sheet is "dogs", then call macro
    > > entitled get dogs. If active sheet is "cats", then call macro entitled
    > > "get Cats".
    > >
    > > Possible...?
    > >
    > > Thanks!!
    > >
    > > D
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***



  6. #6
    Jim Jackson
    Guest

    Re: If activesheet is called X, then do y

    I had forgotten to take out a line. Here is the version that works. Sorry
    about that.


    Sub fill_in()
    ActiveSheet.Range("A3").Select
    For Each cell In Sheets
    Do
    If ActiveCell > "" Then

    ElseIf ActiveCell.Offset(0, 3) > "" Then
    ActiveCell = ActiveCell.Offset(-1, 0)

    ElseIf ActiveCell = "" And ActiveCell.Offset(1, 0) = "" Then
    Exit For
    End If
    ActiveCell.Offset(1, 0).Activate
    Loop
    Next
    End Sub

    --
    Best wishes,

    Jim


    "PCLIVE" wrote:

    > One way I think will work is:
    >
    > if activesheet.name = "dogs" then GetDogs
    > if activesheet.name = "cats" then GetCats
    >
    > However, when is this code supposed to run. Is it based on anytime the
    > sheet is active, or is it dependent on some other code that runs?
    > If it is to run any time those sheets are activated then you could add code
    > specifically to that sheet.
    > For example:
    >
    > Right-click on sheet "dogs" and select View code. Click General dropdown
    > and select Worksheet. Click other dropdown and make sure it is on
    > Activate".
    > Then in your code, enter the macro name you want to run when this sheet is
    > selected. Here's what it would look like:
    >
    > Private Sub Worksheet_Activate()
    > GetDogs
    > End Sub
    >
    >
    > HTH,
    > Paul
    >
    >
    > "Darin Kramer" <[email protected]> wrote in message
    > news:[email protected]...
    > >
    > > Hi guys,
    > >
    > > I need some VBA that says if the active sheet is "dogs", then call macro
    > > entitled get dogs. If active sheet is "cats", then call macro entitled
    > > "get Cats".
    > >
    > > Possible...?
    > >
    > > Thanks!!
    > >
    > > D
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***

    >
    >
    >


+ 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