Macro to filter on every item in a list, then copy filtered range to another worksheet

diygail123

New Member
Joined
Oct 24, 2018
Messages
25
Hi, I wonder if anyone can help me with this, I have a list of vendor codes in column B on a worksheet called "Import", and I need to filter on every vendor code in this list, and copy the filtered range to another worksheet, the name of which will be the vendor code. Below is the code I have recorded, Vendor 000657 being the first vendor that appears when I click on the filter drop down. I can see that the vendor code is being hardcoded, which I dont want, as the vendor codes in the list will change month on month. I can also see that the filtered range is hardcoded, and this is no good either, as this range will change each month.

Can anyone help me? I am a beginner in VBA, but very keen to learn. I was hoping for some kind of loop that filtered on each different vendor code in column B?
Sub New_data()
'
' New_data Macro
'


'FILTER ON FIRST VENDOR
Sheets("Import").Select
ActiveSheet.Range("$A$1:$Q$5000").AutoFilter Field:=2, Criteria1:="000657"

'COPY AND PASTE THE FILTERED RANGE TO VENDOR TAB
Range("A431:F432").Copy
Sheets("657").Select
Range("A4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Import").Select
Range("H431:K432").Copy
Sheets("657").Select
Range("H4").Select
ActiveSheet.Paste

'FILTER ON SECOND VENDOR
Sheets("Import").Select
ActiveSheet.Range("$A$1:$Q$5000").AutoFilter Field:=2, Criteria1:="000661"

'COPY AND PASTE THE FILTERED RANGE TO VENDOR TAB
Range("A226:F232").Copy
Sheets("661").Select
Range("A4").Select
ActiveSheet.Paste
Sheets("Import").Select
Range("H226:K232").Copy
Sheets("661").Select
Range("H4").Select
ActiveSheet.Paste
 
Hi, Recopied the code above and its working fine with F5 now, thanks so much for your help, my spreadsheet is now ready to roll out.

Very grateful

Gail
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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