Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    Run a macro on deactivate? (Excel 2002)

    Hi

    I have this module which works fine, however if the user does not click the button to clear the filter I would like it to run on worksheet deactivate, but if I do I get an error at the line, (Selection.AutoFilter Field:=1)



    Private Sub Worksheet_Deactivate()
    ShipthruClear
    End Sub



    Sub ShipthruClear()
    '
    ' ShipthruClear Macro
    ' Macro recorded 11/07/2005 by XX0824
    '

    '
    Sheets("Shipthrough Form").Unprotect Password:="password"
    Selection.AutoFilter Field:=1 (error here)
    Range("A22").Select

    Sheets("Shipthrough Form").Protect Password:="password"

    End Sub
    If you are a fool at forty, you will always be a fool

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run a macro on deactivate? (Excel 2002)

    If you want to clear the filter, try
    <code>
    Sub ShipthruClear()
    With Sheets("Shipthrough Form")
    .Unprotect Password:="password"
    .ShowAllData
    .Protect Password:="password"
    End With
    End Sub
    </code>
    ShowAllData clears the filter.

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Run a macro on deactivate? (Excel 2002)

    Hi Hans

    Thank you very much that does just what I need


    Braddy
    If you are a fool at forty, you will always be a fool

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •