+ Reply to Thread
Results 1 to 8 of 8

VBA Stopped Working!

Hybrid View

SamuelT VBA Stopped Working! 10-26-2007, 04:56 AM
lecxe Hi Samuel It could be that... 10-26-2007, 07:15 AM
SamuelT Hi lecxe, How would I go... 10-26-2007, 09:46 AM
VBA Noob In a normal module enter this... 10-26-2007, 10:08 AM
SamuelT Thank VBA Noob, ... 10-26-2007, 10:26 AM
  1. #1
    Valued Forum Contributor
    Join Date
    09-23-2005
    Location
    Bristol, UK
    MS-Off Ver
    2007
    Posts
    664

    VBA Stopped Working!

    Hi all,

    I've got the following piece of code that automates two autofilters (one in D7, one in D8).

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Rng As Range
    Dim Str As String
    Set Rng = Range("D11:D118")
    Str = Range("D7").Value
    If Target.Address = "$D$7" Then
          Rng.AutoFilter Field:=3, Criteria1:="*" & Str & "*", Operator:=xlAnd
    End If
    
    Dim Rngx As Range
    Dim Strx As String
    Set Rngx = Range("R11:R118")
    Strx = Range("D8").Value
    If Target.Address = "$D$8" Then
          Rng.AutoFilter Field:=17, Criteria1:="*" & Strx & "*", Operator:=xlAnd
    End If
    
    End Sub
    Now, this was working fine until yesterday when all of sudden, it's stopped working. I've checked security settings and all the jive, and a number of other macros on the sheet still work fine. I've checked the code a number of times, but cannot see what's wrong.

    Can anyone suggest what I might try to get this working again?

    TIA,

    SamuelT

  2. #2
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373
    Hi Samuel

    It could be that you've disabled events. Are the other event procedures working?

    Check the value of

    Application.EnableEvents

    If it's False, set it to True.

    HTH
    lecxe

  3. #3
    Valued Forum Contributor
    Join Date
    09-23-2005
    Location
    Bristol, UK
    MS-Off Ver
    2007
    Posts
    664
    Hi lecxe,

    How would I go about checking this and changing it? My other events also appear not to be working.

    Thanks for the response.

    SamuelT

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    In a normal module enter this and run


    Sub RunMe()
    Application.EnableEvents = True
    End Sub
    Then for your event macro's add

    at the start of code
    Application.EnableEvents =False
    and this at end of code
    Application.EnableEvents = True
    see link. Look for
    Order Of Events
    http://www.cpearson.com/excel/Events.aspx

    HTH

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Valued Forum Contributor
    Join Date
    09-23-2005
    Location
    Bristol, UK
    MS-Off Ver
    2007
    Posts
    664
    Thank VBA Noob,

    Unfortunately, still no joy. One thing which might be affected the event (although I'm not sure why) is the below code which is run via a button click when the user first opens the document. The below example is for all users, although there is similar code for each of nine users:

    Sub All()
    
        Sheets("Refurb 2006").Select
        ActiveSheet.Unprotect Password:="donottouch"
        Selection.AutoFilter Field:=10
        Selection.AutoFilter Field:=2
        Selection.AutoFilter Field:=10, Criteria1:="<>"
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="donottouch"
        
        Sheets("Refurb 2005").Select
        ActiveSheet.Unprotect Password:="donottouch"
        Selection.AutoFilter Field:=10
        Selection.AutoFilter Field:=2
        Selection.AutoFilter Field:=10, Criteria1:="<>"
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="donottouch"
        
        Sheets("Woolwich Retained").Select
        ActiveSheet.Unprotect Password:="donottouch"
        Selection.AutoFilter Field:=10
        Selection.AutoFilter Field:=2
        Selection.AutoFilter Field:=10, Criteria1:="<>"
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="donottouch"
        
        Sheets("Refresh 2007").Select
        ActiveSheet.Unprotect Password:="donottouch"
        Selection.AutoFilter Field:=11
        Selection.AutoFilter Field:=2
        Selection.AutoFilter Field:=11, Criteria1:="<>"
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="donottouch"
    
    
        Sheets("Branch Of The Future").Select
        ActiveSheet.Unprotect Password:="donottouch"
        Selection.AutoFilter Field:=10
        Selection.AutoFilter Field:=2
        Selection.AutoFilter Field:=10, Criteria1:="<>"
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="donottouch"
    
        Sheets("Refresh + Flagship 2008").Select
        ActiveSheet.Unprotect Password:="donottouch"
        Selection.AutoFilter Field:=11
        Selection.AutoFilter Field:=2
        Selection.AutoFilter Field:=11, Criteria1:="<>"
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="donottouch"
    
    
        Sheets("2007 Quickview").Select
        
    End Sub
    Thanks for the assists guys.

    SamuelT

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Do a simple event macro test to rule out that as the cause

    If it's not the event macro then you need to explain why you thought it was

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
    If Target.Value <> "" Then
    MsgBox "Event macro's are running !!"
    End If
    End If
    End Sub
    VBA Noob

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1