Sub RespFilterDenied()
Dim c As Range
Dim Rng As Range
Dim lr As Long
lr = Cells(Rows.Count, "R").End(xlUp).row
Set Rng = Range("A1:X" & lr)
Range("W1:W" & 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:=23, Criteria1:=c.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value
ActiveSheet.Paste
For Each R In ActiveWindow.RangeSelection.Rows
R.RowHeight = 36
Next R
End With
Next c
Sheets("Sheet1").Delete
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub
Solution:
Sub RespFilterDenied()
Dim c As Range
Dim Rng As Range
Dim lr As Long
Dim fn as string
Dim clientName as string
Dim cityName as string
lr = Cells(Rows.Count, "R").End(xlUp).row
Set Rng = Range("A1:X" & lr)
Range("W1:W" & 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:=23, Criteria1:=c.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value
ActiveSheet.Paste
clientName = Range("E2").value
cityName = Range("I2").value
For Each R In ActiveWindow.RangeSelection.Rows
R.RowHeight = 36
Next R
End With
Next c
Sheets("Sheet1").Delete
fn = "D:\" & clientName & "\" & cityName & "\" & format(date,"mmmm") & "\" & replace(date,"/","-") & "\" & cityName & ".xlsx"
ActiveWorkbook.SaveAs fn, xlWorkbookNormal
ActiveWorkbook.Close
End Sub
Obtained from the OzGrid Help Forum.
Solution provided by Trunten.
See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets
See also:
| How to search in subfolders and word documents |
| How to use VBA script to count files/subfolders using a range from WB for the root folder |
| How to input a row variable pertaining to all macros |
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.