Auto Filter of range class failed

ben_sorensen

New Member
Joined
Jun 11, 2015
Messages
44
Hello I keep getting an error that I can't figure out why, I have been racking my brain for hours. I keep getting the auto filter of range class failed and all spelling is correct and there shouldn't be any problems. Here is my code.

PHP:
Sub SplitCodeFilterSheet()
Dim wswb As StringDim wssh As String
wswb = ActiveWorkbook.Namewssh = ActiveSheet.Name

vcolumn = InputBox("Which column would you like to match items", "Match this")
Columns(vcolumn).CopySheets.AddActiveSheet.Name = ("_Summary")range("A1").PasteSpecialColumns("A").RemoveDuplicates Columns:=1, Header:=xlYes
vcounter = range("A" & Rows.Count).End(xlUp).Row
For i = 3 To vcounter
    vfilter = Sheets("_Summary").Cells(i, 1)    ActiveWorkbook.Sheets(wssh).Activate    ActiveSheet.Cells(i, vcolumn).Select       ActiveSheet.AutoFilterMode = False   ActiveSheet.Columns.AutoFilter field:=Columns(vcolumn).Column, Criteria1:=vfilter    Cells.Copy    Workbooks.Add    range("A2").PasteSpecial    If vfilter <> "" Then        ActiveWorkbook.SaveAs ThisWorkbook.Path & "\Reports\" & vfilter                Else                 ActiveWorkbook.SaveAs ThisWorkbook.Path & "\Reports\_Blank"             End If        ActiveWorkbook.Close        Workbooks(wswb).Activate    Next i
Sheets("_Summary").Delete

    



End Sub

Any help would be most apprciated

Best
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Apologies the code there looks sloppy:

Code:
Sub SplitCodeFilterSheet()


Dim wswb As String
Dim wssh As String


wswb = ActiveWorkbook.Name
wssh = ActiveSheet.Name




vcolumn = InputBox("Which column would you like to match items", "Match this")


Columns(vcolumn).Copy
Sheets.Add
ActiveSheet.Name = ("_Summary")
range("A1").PasteSpecial
Columns("A").RemoveDuplicates Columns:=1, Header:=xlYes


vcounter = range("A" & Rows.Count).End(xlUp).Row


For i = 3 To vcounter


    vfilter = Sheets("_Summary").Cells(i, 1)
    ActiveWorkbook.Sheets(wssh).Activate
    ActiveSheet.Cells(i, vcolumn).Select
    
   ActiveSheet.AutoFilterMode = False
   ActiveSheet.Columns.AutoFilter field:=Columns(vcolumn).Column, Criteria1:=vfilter
    Cells.Copy
    Workbooks.Add
    range("A2").PasteSpecial
    If vfilter <> "" Then
        ActiveWorkbook.SaveAs ThisWorkbook.Path & "\Reports" & vfilter
        
        Else
        
         ActiveWorkbook.SaveAs ThisWorkbook.Path & "\Reports\_Blank"
         
    End If
    
    ActiveWorkbook.Close
    
    Workbooks(wswb).Activate
    
Next i


Sheets("_Summary").Delete




    








End Sub
 
Last edited:
Upvote 0
Your code works for me.
Do you get the error on the 1st run through, or do some workbooks get created?
 
Upvote 0
So it goes through the process of creating the other worksheet, pasting all that info and removing duplicates from those pasted values, then it pops an error for the runtime error. When I tell it to debug it highlights the filter line
 
Upvote 0
Any merged cells?
Is the sheet protected?
 
Upvote 0
No none of that, the info that I am copying is in column J and it copies to the other page in column A then it uses those values to filter on column J and that is where the error is coming in. Column J I had a vlookup that I pasted special values to hard code those in thinking that may be the issue, but that isn't so I am not sure where I am getting an error.
 
Upvote 0
Is your data in a proper table?
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top