Order Template with vba to select distinct values and then loop through on those values in XL2007

mntrapper

New Member
Joined
Nov 7, 2014
Messages
2

<colgroup><col width="69"><col span="7" width="64"><col width="71"><col width="85"></colgroup><tbody>
</tbody>
Hi
I am hoping to learn how to setup a unique list of vendors (VendorList) from a list using a named range, then loop through that list in a VBA macro that is using filters. Each worksheet is named after the vendor and so is the table. So worksheet Vendor1 table Vendor1. My main sheet is called Orders and where we import all of the items to be ordered for the day. I know what vendors I have but not all will be ordered daily. I will add sheets to the workbook as we add vendors and I thought that this should be fairly simple but the simplicity has alluded me. We then do a print of each worksheet that had an order for the day. Thank you in advance.

So basically loop through unique list of vendors VendorList and do this code for each i in VendorList
Sheets("ORDERS").Select
ActiveSheet.ListObjects("Orders").Range.AutoFilter Field:=2, Criteria1:= _
"i"
Do While Range("Orders") <> ""
Range("Orders").Select
Selection.Copy
Sheets("i").Select
Range("i").Select
ActiveSheet.Paste
ActiveWindow.SelectedSheets.PrintPreview

[TABLE="width: 196"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]VendorName
[/TD]
[TD]ProductID[/TD]
[/TR]
[TR]
[TD]Vendor1[/TD]
[TD]Vendor18969-01[/TD]
[/TR]
[TR]
[TD]Vendor1[/TD]
[TD]Vendor18969-02[/TD]
[/TR]
[TR]
[TD]Vendor1[/TD]
[TD]Vendor18969-03[/TD]
[/TR]
[TR]
[TD]Vendor1[/TD]
[TD]Vendor18969-04[/TD]
[/TR]
[TR]
[TD]Vendor2[/TD]
[TD]Vendor28969-04[/TD]
[/TR]
[TR]
[TD]Vendor2[/TD]
[TD]Vendor28969-05[/TD]
[/TR]
[TR]
[TD]Vendor2[/TD]
[TD]Vendor28969-06[/TD]
[/TR]
[TR]
[TD]Vendor2[/TD]
[TD]Vendor28969-07[/TD]
[/TR]
[TR]
[TD]Vendor2[/TD]
[TD]Vendor28969-08[/TD]
[/TR]
[TR]
[TD]Vendor2[/TD]
[TD]Vendor28969-15[/TD]
[/TR]
[TR]
[TD]Vendor3[/TD]
[TD]Vendor38969-15[/TD]
[/TR]
[TR]
[TD]Vendor3[/TD]
[TD]Vendor38969-16[/TD]
[/TR]
[TR]
[TD]Vendor3[/TD]
[TD]Vendor38969-16[/TD]
[/TR]
[TR]
[TD]Vendor3[/TD]
[TD]Vendor38969-16[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I found this which is similar to what I want to do but I am using a table so how does that affect the code? Any help is appreciated!!!
Sub AutoLoop()
Dim c As Range
Dim rng As Range
Dim LR As Long

LR = Cells(Rows.Count, "B").End(xlUp).Row
Set rng = Range("A1:AJ" & LR)

Range("E1:E" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AM1"), Unique:=True

For Each c In Range([AM2], Cells(Rows.Count, "AM").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=5, Criteria1:=c.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value
ActiveSheet.Paste
End With
Next c

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
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