VBA code to adding additional filter with array

Balajibenz

Board Regular
Joined
Nov 18, 2020
Messages
80
Office Version
  1. 2013
Platform
  1. Windows
I have below code which i use for copying the filtered data to another sheet(ws2).
VBA Code:
Sub VBA()

ws1.Activate
    lr = ws1.Cells(Rows.Count, 16).End(xlUp).Row
    For Each c In ws1.Range("P2:P" & lr)
        temp2 = Left(c, 3)
        temp = Right(c, 3)
        temp3 = c.Offset(0, -5)
            If temp2 = "180" And _
        (temp = "341" Or _
        temp = "342" Or _
        temp = "642") Then
        
    
        ReDim Preserve arr(i)
            arr(i) = CStr(c)
            i = i + 1
        End If    
    With ws1.Range("A1").CurrentRegion
        .AutoFilter 16, Array(arr), 7
        .Offset(1).Copy ws2.Cells(2, 1)
        .AutoFilter
    End Sub

what i am looking for right now to is to add another filter in column K, I have defined it as temp3 in above code and looking to include filter as temp3 = "Sam" or "Alok" or "Kristy". Can someone help me with this.. Thanks in advance.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
is to add another filter in column K
Add the following highlighted line and test.
Rich (BB code):
  With ws1.Range("A1").CurrentRegion
    .AutoFilter 16, Array(arr), 7
    .AutoFilter 11, Array("Alok", "Kristy", "Sam"), 7
    .Offset(1).Copy ws2.Cells(2, 1)
    .AutoFilter
  End With
 
Upvote 0
Solution
i wanted to copy from columns A to H
Try this:

VBA Code:
  With ws1.Range("A1").CurrentRegion
    .AutoFilter 16, Array(arr), 7
    .AutoFilter 11, Array("Alok", "Kristy", "Sam"), 7
    ws1.AutoFilter.Range.Range("A2:H" & lr).Copy ws2.Cells(2, 1)
    .AutoFilter
  End With
 
Upvote 0

Forum statistics

Threads
1,224,739
Messages
6,180,674
Members
452,993
Latest member
FDARYABEE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top