How to fix "Compile error: Expected End Sub" in VBA Macro?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dorota Prywata
    New Member
    • Feb 2011
    • 1

    How to fix "Compile error: Expected End Sub" in VBA Macro?

    Hi,

    I need help with VBA Macro for Auto-filter to high lite a header plp advice as per below course a I got Compile error: Expected End Sub ?

    Code:
    Sub Macro1()
    
    Function FilterOn(myCell As Range) As Boolean
        On Error Resume Next
        With myCell.Parent.AutoFilter
            With .Filters(myCell.Column - .Range.Column + 1)
                If .On Then FilterOn = True
            End With
        End With
    End Function
    
    End Sub

    Thanks, D
    Last edited by Stewart Ross; Feb 3 '11, 01:15 PM. Reason: added code tags
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    You can't define a function (lines 3-10) WITHIN the definition of a SUB (lines 1 and 12). You can CALL the function from the sub, but they must be separately defined.

    -Stewart

    Comment

    Working...