Results 1 to 3 of 3

Loop code for selected worksheets

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Smile Loop code for selected worksheets

    Hello, could some one please help modify my code to do the following:

    I am trying to create a loop that will only loop through worksheets named: E-1, E-2 and E-7 only in my Excel 2003 workbook (attached with dummy data).

    The AutoFilters for each of these worksheets: E-1, E-2, E-3, E-7, E-9, E-11 are switch on and have filters applied.

    Upon each iteration of looping through the macro, the following line of code is executed. This code works fine for the first iteration loop, however I the following iterations to paste the filtered data to worksheet named: 1 Mth in the last cell (so that the data is appended).

    I do not know how to make this happen

    So if some one could please help me modify my macro and make it so that the data is appended in worksheet named 1 Mth, then it would be greatly appreciated.

    Kind regards,

    Chris

      Destination:=Worksheets("1 Mth").Range("A101")
    Sub Test2()
    '
    '
    Dim ProcessWS As Boolean
    Dim ws As Worksheet
    
    ProcessWS = False
    
    Set ws = Worksheets("E-1").Select
    
    For Each ws In ThisWorkbook.Worksheets
    
    If ws.Name = "E-1" Then ProcessWS = True
    If ws.Name = "E-2" Then ProcessWS = True
    If ws.Name = "E-7" Then ProcessWS = True
    If ws.Name = "E-3" Then ProcessWS = False
    If ws.Name = "E-9" Then ProcessWS = False
    If ws.Name = "E-11" The ProcessWS = False
    
    If ProcessWS Then
    
        With ActiveSheet.AutoFilter.Range
            On Error Resume Next
            Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
            .SpecialCells(xlCellTypeVisible)
            On Error GoTo 0
        End With
        
    If Not rng2 Is Nothing Then
    
        Set rng = ActiveSheet.AutoFilter.Range
        rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
        Destination:=Worksheets("1 Mth").Range("A101")
        
    End If
        
    
    End If
    Next
    
    End Sub
    Attached Files Attached Files
    Last edited by longbow007; 06-16-2010 at 11:57 PM.

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