Consulting

Results 1 to 2 of 2

Thread: Loop sheets that begin with given chars

  1. #1
    VBAX Regular
    Joined
    Jul 2019
    Posts
    36
    Location

    Loop sheets that begin with given chars

    I would like to loop each sheet and perform some action for those sheets that start with REDS.

    I have written some code, but erroring.

    Sub LoopSheets()
    
    Dim mWB As Workbook
    Dim mWS As Worksheet
    Dim arySheets
    Dim sFile
    Dim iSheet As Long
    
    
    With ActiveWorkbook
    
    
    'If sFile <> False Then
    Set mWB = ActiveWorkbook.Worksheets(I).Name Like "REDS*"
    Debug.Print ActiveWorkbook.Worksheets(I).Name
    ReDim arySheets(mWB.Worksheets.Count)
    For Each oWS In mWB.Worksheets
    
    
    '''my code here.
    
    
    
    
    Next mWS
    
    
    
    
    End With
    
    
    
    
    End Sub

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    374
    Location
    Oh, a lot of mistakes in this code.
    Try this
    Sub LoopSheets()
    
        Dim oWS         As Worksheet
        Dim I           As Long
    
        With ActiveWorkbook
    
            For I = 1 To .Worksheets.Count
                
                If UCase(.Worksheets(I).Name) Like UCase("Reds*") Then
                    
                    Set oWS = .Worksheets(I)
                    Debug.Print oWS.Name
    
                    '''my code here.
    
                End If
    
            Next I
    
        End With
    
    End Sub
    or that
    Sub LoopSheets1()
        Dim oWS         As Worksheet
    
        With ActiveWorkbook
    
            For Each oWS In .Worksheets
                If UCase(oWS.Name) Like UCase("RedS*") Then
    
                    Debug.Print oWS.Name
    
                    '''my code here.
    
                End If
    
            Next oWS
    
        End With
    
    End Sub
    Artik

Tags for this Thread

Posting Permissions

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