Hello everyone,
I found this script on a video and entered into excel. What I'm looking at is to take my customers items copy that data and create a new workbook with that data and would like to copy the header row into each sheet. The script I have asks you to Pick the column to sort and use as for the data to create the workbooks, but I get an error on the Autofilter section of the code. In the video it works, after doing research I haven't been able to see why it is having an issue. Any help is appreciated.
The line of code I'm getting the error on is:
Error message is: autofilter method of range class failed
Thank you for your time looking at this,
Fred
I found this script on a video and entered into excel. What I'm looking at is to take my customers items copy that data and create a new workbook with that data and would like to copy the header row into each sheet. The script I have asks you to Pick the column to sort and use as for the data to create the workbooks, but I get an error on the Autofilter section of the code. In the video it works, after doing research I haven't been able to see why it is having an issue. Any help is appreciated.
Code:
Sub Split()
Dim wswb As String
Dim wssh As String
wswb = ActiveWorkbook.Name
wssh = ActiveSheet.Name
vColumn = inputbox("Please indicate which column (i.e. A, B, C,...), you would like to split by","Column selection")
Columns(vColumn).Copy
Sheets.Add
ActiveSheet.Name = "_Summary"
Range("A1").PasteSpecial
Columns("A").RemoveDuplicates Columns:=1, header:=x1Yes
vCounter = Range("A" & Rows.Count).end(xlUp).Row
For i = 2 To vCounter
vFilter=Sheets("_Summary").Cells(i, 1)
Sheets(wssh).Activate
ActiveSheet.Columns.AutoFilter field:=Columns(vColumn).Column, Criteria1:=vfilter
Cells.Copy
Workboks.Add
Range("A1").PasteSpecial
If vfilter <> "" Then
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\split results\" & vfilter
Else
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\split results\_Empty"
End If
ActiveWorkbook.Close
Workbooks(wswb).Activate
Next i
Sheets("_Summary").Delete
End Sub
The line of code I'm getting the error on is:
Code:
ActiveSheet.Columns.AutoFilter field:=Columns(vColumn).Column, Criteria1:=vfilter
Error message is: autofilter method of range class failed
Thank you for your time looking at this,
Fred