Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Test for Sheet Name (VBA/Excel/2002-3)

    I cannot work out how to test for a sheet name in VBA.

    I have four sheets and I want to do something along the following lines:
    <pre> If Worksheets("Sheet1").Select = True Then
    Statement1
    ElseIf Worksheets("Sheet2").Select = True Then
    Statement2
    ...
    End If</pre>

    The above does not work. Some filtering will be done depending on the current sheet name therefore I want to test for the sheet name.

    Any suggestions greatly appreciated.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Test for Sheet Name (VBA/Excel/2002-3)

    Select is not a property, but a method: it selects a worksheet. The currently active worksheet is ActiveSheet.

    Select Case ActiveSheet.Name
    Case "Sheet1"
    Statement1
    Case "Sheet2"
    Statement2
    ...
    End Select

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Test for Sheet Name (VBA/Excel/2002-3)

    As always, many thanks Hans

    Enjoy your weekend.

Posting Permissions

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