Passing a Variable to a Macro
Hi
Create a list with all territories and name it as "MyNamedRange". This
should do it:
Sub LoopFilter()
Application.ScreenUpdating = False
Dim DataSh As Worksheet
Set DataSh = ActiveSheet ' Or refer to a specific sheet like:
Worksheets("Sheet1")
DataSh.Activate
Range("$A$5:$CW$355").Select
For Each cell In DataSh.Range("MyNamedRange").Cells
If cell.Value = "" Then Exit For ' exit when next cell in
MyNamedRange is empty
MyCriteria = cell.Value
Selection.AutoFilter Field:=1, Criteria1:=MyCriteria
Set newSh = Sheets.Add(after:=Sheets(Sheets.Count))
newSh.Name = MyCriteria
DataSh.Activate
Selection.Copy Destination:=newSh.Range("A1") ' change range to
suit
Next
Selection.AutoFilter
Application.ScreenUpdating = True
End Sub
Regards,
Per
On 9 Dec., 14:32, IAM wrote:
Wow. That was super easy. Of course it opens up many more possibilities in my
mind.
I there any way to give a pick list from a named range in the excel sheet
for a variable in the criteria for this macro?
OR
Is there any way to loop this macro so it keeps feeding in variables from a
range in the document until there are no more? The rest of this macro takes
the filtered list and copies to a new sheet. This allows a master list of
sales opportunity to be broekn out and formatted for each territory...
Iam
|