自动过滤器循环通过另一张纸的标准

时间:2016-11-22 22:43:08

标签: excel vba excel-vba

有人可以编辑我的宏脚本,以便在Range(“A2”)之后再次运行到下一个条件吗?我尝试使用Do循环并将Range编辑为(“A2:A5”),但它不起作用。请帮忙:(

Sub Macro3()
Do
'This part should autofilter the data based on the names in the "Manager_List" tab
Selection.AutoFilter Field:=2, Criteria1:=Worksheets("Manager_List").Range("A2").Value
'After it filters the data, it will copy and paste to a new workbook
Range("A1:W1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("A:V").Select
Columns("A:V").EntireColumn.AutoFit

Application.DisplayAlerts = False
Sheets(Array("Sheet2", "Sheet3")).Select
Sheets("Sheet3").Activate
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Range("A1").Select
'This part will save the new workbook that contains the data of specific team manager. 
'After saving it should close the new workbook and go back to the master file     
Dim Path As String
Dim filename As String
Path = "C:\Users \Documents\Sept Results_"
filename = Range("A2")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsb", FileFormat:=50
ActiveWindow.Close
'Id like it to run again to the next cell in (Criteria1:=Worksheets("Manager_List").Range("A2").Value) - so that should be A3 until it reaches the blank cell before it stops.
Loop Until ActiveCell.Value = ""
End Sub

0 个答案:

没有答案