Compile Error: Sub or Function not defined

johnmerlino

Board Regular
Joined
Sep 21, 2010
Messages
94
Hey all,

I have a macro that filters out data using auto filter. Problem is once everything is complete, I only want to keep the visible cells and destroy everything else. So I added a For Each In loopm to iterate through active cells and set their auto filter mode to false, which hopefully removes any filtering. Unfortunately it gives me a compire error highlighting the text "specialCell":
Code:
Sub sortify()
'
' sortify Macro
'
' Keyboard Shortcut: Ctrl+Shift+S
'
    Application.ScreenUpdating = False
    
    Range("A1:E519").Select
    Selection.Cut Destination:=Range("A2:E520")
    Range("A2:E520").Select
    
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "A "
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "B"
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "C"
    Range("D1").Select
    Range("D1").Select
    ActiveCell.FormulaR1C1 = "D"
    Range("E1").Select
    ActiveCell.FormulaR1C1 = "E"
    Range("A1").Select
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$E$520"), , xlYes).Name = _
        "Table1"
    Range("Table1[#All]").Select
    ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight8"
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _
        "=Real Prop*", Operator:=xlAnd
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=2, Criteria1:= _
        "=DF*", Operator:=xlAnd
        
    ActiveSheet.ListObjects("Table1").Sort.SortFields.Clear
    ActiveSheet.ListObjects("Table1").Sort.SortFields.Add _
        Key:=Range("Table1[[#All],[E]]"), SortOn:=xlSortOnValues, Order:= _
        xlAscending, DataOption:=xlSortNormal
    With ActiveSheet.ListObjects("Table1").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Columns("C:E").Select
    Selection.Cut
    Selection.SpecialCells(xlCellTypeVisible).Select
    Range("F1").Select
    ActiveSheet.Paste
    
    Columns("A:E").Select
    Selection.EntireColumn.Hidden = True
    
    Rows("1:1").Select
    Range("F1").Activate
    Selection.EntireRow.Hidden = True
    
    For Each cell In SpecialCells(xlCellTypeVisible)
    cell.AutoFilterMode = False
    End With
    
    
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I think you are missing the range or cell part of this statement?

For Each cell In cells.SpecialCells(xlCellTypeVisible)

Maybe that helps?
 
Upvote 0
It then gives me error "end with without with"

Also, do you think this for each loop will remove all the auto filtering from visible cells? I'm hoping it will.
 
Upvote 0
It then gives me error "end with without with"


Code:
    For Each cell In SpecialCells(xlCellTypeVisible)
    cell.AutoFilterMode = False
    End With

Change to

Code:
    For Each cell In SpecialCells(xlCellTypeVisible)
    cell.AutoFilterMode = False
    Next
 
Upvote 0
Now it says object doesn't support this property or method. "cell.AutoFilterMode = False"
So basically it's saying AutoFilterMode is not a property of the cell object. Now presumably if this works like any other programming language, cell should refer to the current index of visible cells, so am I missing something here?

Thanks for response.
 
Upvote 0
To be honest, I don't know as I have never use specialcells but doesn't autofilter (or the removal of) work on a range as opposed to a cell?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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