Filter Sheet2 Data based on Sheet1 List Values

pwill

Active Member
Joined
Nov 22, 2015
Messages
406
Hi can anyone help with a macro?

I have many hundreds of rows of Data on Sheet2 "A1:Z" with headers.
"A2:A" has 'Ref values' for each row of Data.

Sheet1 column "R5:R" has 'Ref values' added that change daily.

I want to Filter Sheet2 "A:Z" using "A2:A" as field, based on the Values entered on Sheet1
"R5:R" and then copy the filtered Data to last row on Sheet3

Sheet2 Data example

ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1RefCntRefCntRefCntRefCnt
212118131132
312118131132
412118131132
52627214216
62627214216
72627214216
835324330333
935324330333
1035324330333
114245410424
124245410424
134245410424
14518521522533
15518521522533
16518521522533
1769621629632
1869621629632
1969621629632
20720725727731
21720725727731
22720725727731
23
24
25

<tbody>
</tbody>

If Sheet1 column "R5:R9" has values 1,2,4,6,7 then the copied filtered Data on Sheet3 would be

ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1RefCntRefCntRefCntRefCnt
212118131132
312118131132
412118131132
52627214216
62627214216
72627214216
84245410424
94245410424
104245410424
1169621629632
1269621629632
1369621629632
14720725727731
15720725727731
16720725727731
17
18
19
20
21
22
23
24
25

<tbody>
</tbody>

Any help would be appreciated

regards

pwill
<strike>
</strike>
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi can anyone help with a macro?

I have many hundreds of rows of Data on Sheet2 "A1:Z" with headers.
"A2:A" has 'Ref values' for each row of Data.

Sheet1 column "R5:R" has 'Ref values' added that change daily.

I want to Filter Sheet2 "A:Z" using "A2:A" as field, based on the Values entered on Sheet1
"R5:R" and then copy the filtered Data to last row on Sheet3


If Sheet1 column
"R5:R9" has values 1,2,4,6,7 then the copied filtered Data on Sheet3 would be

ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1RefCntRefCntRefCntRefCnt
212118131132
312118131132
412118131132
52627214216
62627214216
72627214216
84245410424
94245410424
104245410424
1169621629632
1269621629632
1369621629632
14720725727731
15720725727731
16720725727731
17

<tbody>
</tbody>

Any help would be appreciated
regards
pwill

You can check your example, on sheet 1, in cells R5:R9 the values ​​are 14,14,14,10,10.


Also tell me in which row the headings are on sheet1. The names of the headings of sheet1 are the same as those of sheet2.


After reviewing the R5:R9 range, can you explain, according to your example, what data should be copied?
 
Upvote 0
Hi DanteAmor,

I didn't give an example for sheet1, the above example is the Data on sheet2 and the output on sheet3 if 'Sheet1 column "R5:R9" had values 1,2,4,6,7'

The headers are the same on sheet2 and sheet3
There are no headers on sheet1

The data that should be copied would be
Sheet2 "A2:Z" when applying the filter to 'column A or field 1 on sheet2 to only show the values from Sheet1

Sheet1 values
"R5" = 1
"R6" = 2
"R7" = 4
"R8" = 6
"R9" = 7

hope that makes more sense?

regards
 
Last edited:
Upvote 0
:oops: My mistake, I thought it was the sheet1.Try this


Code:
Sub Filter_with_multiple_conditions()
    Dim c As Range, n As Long, arr() As Variant
    For Each c In Sheets("Sheet1").Range("R5", Sheets("Sheet1").Range("R" & Rows.Count).End(xlUp))
        ReDim Preserve arr(n)
        arr(n) = c.Text
        n = n + 1
    Next
    Sheets("Sheet2").UsedRange.AutoFilter Field:=1, Criteria1:=arr, Operator:=xlFilterValues
    Sheets("Sheet2").AutoFilter.Range.Offset(1).EntireRow.Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp)(2)
End Sub
 
Upvote 0
Hi DanteAmor,
Thanks for your reply I've been working all day I will give it a try and let you know how I get on
Much appreciated ;)

pwill
 
Last edited:
Upvote 0
Hi DanteAmor,
Thanks for your reply I've been working all day I will give it a try and let you know how I get on
Much appreciated ;)

pwill

Ok, Let me know if you have any doubt.
 
Upvote 0
:oops: My mistake, I thought it was the sheet1.Try this


Code:
Sub Filter_with_multiple_conditions()
    Dim c As Range, n As Long, arr() As Variant
    For Each c In Sheets("Sheet1").Range("R5", Sheets("Sheet1").Range("R" & Rows.Count).End(xlUp))
        ReDim Preserve arr(n)
        arr(n) = c.Text
        n = n + 1
    Next
    Sheets("Sheet2").UsedRange.AutoFilter Field:=1, Criteria1:=arr, Operator:=xlFilterValues
    Sheets("Sheet2").AutoFilter.Range.Offset(1).EntireRow.Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp)(2)
End Sub


Works perfect, thank you DanteAmor :)

pwill
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,284
Members
448,885
Latest member
LokiSonic

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