+ Reply to Thread
Results 1 to 4 of 4

VBA based conditional formatting (>3 formats needed)

Hybrid View

  1. #1
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    The reason that the macro is no longer working is that it crashed or was stopped after this line of code was run
    Application.EnableEvents = False
    and before this line of code was run
    Application.EnableEvents = True
    Place this macro on the same module sheet as your Worksheet Change macro and run it manually

    Sub ReEnableEvents()
    Application.EnableEvents = True
    End Sub
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  2. #2
    Registered User
    Join Date
    10-15-2004
    Posts
    2
    Mudraker: That works! Cheers mate.

    Roy: I left out some other formats for the sake of shortening the code to pasted here. I'm actually using 7 different formats.

    I fixed the quotes and it was still throwing errors so I poked around in the debugger and realized Rng was null until inside the for loop. So I moved that line of code. Here's the code that works for me.

    Private Sub Worksheet_Change(ByVal Target As Range)
       
       Dim Rng As Range
       Dim RowRng As Range
       Dim iColour As Integer
     
       For Each Rng In Target
          
          Set RowRng = Range(Rng.Offset(0, -9), Rng)
          
          If Not Application.Intersect(Rng, Range("J1:J100")) Is Nothing Then
                    
             Application.EnableEvents = False
             
             Select Case Rng.Value
                Case Is = "ahead"
                   iColour = 3
                Case Is = "on time"
                   iColour = 45
                Case Is = "behind"
                   iColour = 50
                Case Else
                   iColour = 0
             End Select
             
             If iColour = 0 Then
                RowRng.Interior.ColorIndex = xlNone
             Else
                RowRng.Interior.ColorIndex = iColour
             End If
             
          End If
          
       Next Rng
       
       Application.EnableEvents = True
       
    End Sub

+ 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