lewysedmunds
New Member
- Joined
- Sep 29, 2021
- Messages
- 5
- Office Version
- 2019
- 2016
- 2013
- Platform
- Windows
- MacOS
- Mobile
- Web
Hi all,
First time poster - long time reader ?
I have a workbook that for every "Site Code" in Column A, filter & copy all data down and right then save as new worksheet with Site Code and todays date in the title.
Currently the code I have (scavanged from forums) is below:
I keep facing the error: AutoFilter method of Range class failed.
I have googled, but as of yet I have no idea what it could be!
First time poster - long time reader ?
I have a workbook that for every "Site Code" in Column A, filter & copy all data down and right then save as new worksheet with Site Code and todays date in the title.
Currently the code I have (scavanged from forums) is below:
VBA Code:
Sub Filter_SiteCode()
Dim sh1 As Worksheet, SiteCode As Range, wb As Workbook
Set sh1 = Sheets("Sheet1")
For Each SiteCode In sh1.Range("A1", sh1.Cells(Rows.Count, 2).End(xlUp))
sh1.UsedRange.AutoFilter 24, SiteCode.Value
If sh1.Cells(Rows.Count, 1).End(xlUp).Row > 1 Then
Set wb = Workbooks.Add
sh1.UsedRange.SpecialCells(xlCellTypeVisible).Copy
wb.Sheets(1).Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
wb.Sheets(1).Range("A1").PasteSpecial xlPasteFormats
wb.SaveAs "S:\Audits\1. AM Reviews\XXXX\Daily XXX Quality Review" & "\" & SiteCode.Value & "".xlsx"
wb.Close False
sh1.AutoFilterMode = False
End If
Next
End Sub
I keep facing the error: AutoFilter method of Range class failed.
I have googled, but as of yet I have no idea what it could be!