+ Reply to Thread
Results 1 to 14 of 14

Filter data and copy visible cells based on criteria

Hybrid View

  1. #1
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Filter data and copy visible cells based on criteria

    Quote Originally Posted by YasserKhalil View Post
    Thanks a lot for this wonderful help ..
    By the way how can I say (Bear with me ..) I mean ...
    You are welcome.
    Yes, I know
    It has been a while since I am being involved in some of your threads. I just made a joke to make it not too boring.
    The bear, I mean, like the grizzly bear, polar bear, ....

    -----

    One way is to save the filtered rows of AutoFilter to a variable (in my code below it is called filteredRows), and then you can use this var as many time as needed, together with intersect method, to get intersection area of expected columns.

    Sub Test()
      Dim arrRngA(1 To 3) As Range, arrRngB(1 To 3) As Range, filteredRows As Range
      Dim i As Long, total As Long
    
      Application.ScreenUpdating = False
    
      For i = 1 To UBound(arrRngA)
          Set arrRngA(i) = Worksheets("0" & i & "A").Range("C6")
          Set arrRngB(i) = Worksheets("0" & i & "B").Range("AE6")
          arrRngA(i).Resize(1000, 10).ClearContents  '.Resize(1000, 10) = 1000 rows x 10 columns (C:L)
          arrRngB(i).Resize(1000).ClearContents
          arrRngA(i).Parent.Visible = xlSheetVeryHidden
          arrRngB(i).Parent.Visible = xlSheetVeryHidden
      Next i
    
      With Sheets("Data")
        .AutoFilterMode = False
         With .Range("B1").CurrentRegion
           .AutoFilter field:=3, Criteria1:=.Parent.Range("I1").Value
            With .Columns(1).Offset(1).SpecialCells(xlCellTypeVisible)
              total = .Count
              Set filteredRows = .EntireRow
            End With
         End With
        .AutoFilterMode = False
      
        If total >= 2 Then
           arrRngA(1).Parent.Visible = xlSheetVisible
           Intersect(filteredRows, Sheet1.Columns("B")).Copy arrRngA(1)
           Intersect(filteredRows, Sheet1.Columns("V:X")).Copy arrRngA(1).Offset(0, 1)
           Intersect(filteredRows, Sheet1.Columns("P:U")).Copy arrRngA(1).Offset(0, 4)
    
           arrRngB(1).Parent.Visible = xlSheetVisible
           Intersect(filteredRows, Sheet1.Columns("K")).Copy arrRngB(1)
        Else
           Exit Sub
        End If
      End With
    
      For i = 1 To (UBound(arrRngA) - 1)
          With arrRngA(i).Offset(29).Resize(1000, 10)
            If Not IsEmpty(.Cells(1)) Then
               .Copy arrRngA(i + 1)
               .ClearContents
               arrRngA(i + 1).Parent.Visible = xlSheetVisible
            Else
               Exit For
            End If
          End With
          With arrRngB(i).Offset(29).Resize(1000)
            .Copy arrRngB(i + 1)
            .ClearContents
            arrRngB(i + 1).Parent.Visible = xlSheetVisible
          End With
      Next i
    
      If total > 29 * UBound(arrRngA) Then MsgBox "Not enough sheets to divide data properly"
      Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. copy, paste visible cells after Auto filter- VBA
    By meus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2015, 01:59 AM
  2. filter data based on criteria and copy to another sheet
    By anbarasi_r in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2015, 09:56 PM
  3. Advanced Filter Copy visible cells only
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-22-2015, 03:28 AM
  4. [SOLVED] Copy Filter Data and paste it on another workbook with special cells(Only Visible Cells)
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-13-2014, 07:59 AM
  5. Macro to filter data and copy the data's from multiple columns based on the criteria
    By millatshawn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2014, 08:14 AM
  6. Need VBA help to filter and copy data based on specific criteria
    By astrial in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-13-2013, 10:48 AM
  7. Copy to Visible cells after filter
    By vandanavai in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2009, 01:29 PM

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