Select sheets using VBA whose name contain specific word (word from variable)

  • Select sheets using VBA that contain specific word (word from variable).


    I want to select all sheets in active workbook whose name contains a specific word. I getting such specific word from variable.


    Thanks
    Amir

  • Re: Select sheets using VBA whose name contain specific word (word from variable)


    You need to explain more explicitly about how your are referencing the sheet name variable.


    Here is basic start:


    Code
    Dim strSheetName As String
    
    
    strSheetName = "Whatever"
    
    
    Worksheets(strSheetName).Select
  • Re: Select sheets using VBA whose name contain specific word (word from variable)


    The word should be part of the total sheet name. For example, I want to search for word "alpha" in all the sheet names and select the sheets that contain alpha word. Sheet name could be "Alpha_Analysis" and the code has to select such sheet.


    Thanks

  • Re: Select sheets using VBA whose name contain specific word (word from variable)


    Actually, I have a lot of sheets that contains different names. For example, I have 6 sheets named as Alpha_A, Alpha_B, Alpha_C, Beta_A, Beta_B, Beta_C. Now I want to select all sheets that contain word "Alpha" word in it.

  • Re: Select sheets using VBA whose name contain specific word (word from variable)


    try

    Code
    Sub test()
    Dim ws As Worksheet, flg As Boolean
    For Each ws In Sheets
        If LCase(ws.Name) Like "*alpha*" Then
            ws.Select Not flg
            flg = True
        End If
    Next
    End Sub
  • Re: Select sheets using VBA whose name contain specific word (word from variable)


    I know this is an old post, but I am trying to find out how to add more than one sheet name to something like this:


    Code
    If ws.Name Like "Schedule" Then


    The code works fine for the worksheet "Schedule", but now i have another sheet called "jobs"


    How can I re-write this line to do the script in both sheets? "Schedule" and "jobs" (the script is part of a workbook script ..so should be fine....


    thanks

  • Re: Select sheets using VBA whose name contain specific word (word from variable)


    Please do not post questions in threads started by other members.


    Start your own thread. Give it an accurate and concise title that summarises your problem and explain your issue fully. If you think another tread can help clarify your problem, you can include a link to that thread by copying the UR: from the address bar of your browser and pasting into your message.

  • Re: Select sheets using VBA whose name contain specific word (word from variable)


    sorry...I thought this would be easier since it seemed so similar...but thank you, I will start a new thread..

  • Re: Select sheets using VBA whose name contain specific word (word from variable)


    Just to clarify - at the time I replied I was a Moderator on this forum. As the post does not follow the board rules, see point 2c here, the OP was asked to start his own thread which he agreed to do.


    It was, and still is, a simple matter to view all his/her posts and find the new thread.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!