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

    Author
    Topic
    #421869

    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:

        If Worksheets("Sheet1").Select = True Then
            Statement1
        ElseIf Worksheets("Sheet2").Select = True Then
            Statement2
        ...
        End If

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #960019

      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

    Viewing 0 reply threads
    Reply To: Test for Sheet Name (VBA/Excel/2002-3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: