+ Reply to Thread
Results 1 to 5 of 5

IF statement with Conditional Formatting.

Hybrid View

  1. #1
    Registered User
    Join Date
    07-05-2011
    Location
    London, England
    MS-Off Ver
    Excel 2000
    Posts
    3

    Question IF statement with Conditional Formatting.

    Hi,
    I have a performance spreadsheet which is setup to identify how different services are performing. I use the code below to identify the performace. This code does not update when I use IF statement or any simple formula. For example IF(A1=10,"h","hh"), this will not be update the colour once I have changed cell A1 to 10, although the formula will work and change to "h".
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        On Error GoTo ws_exit:
        Application.EnableEvents = False
        If Not Intersect(Target, Range("A1:V1000")) Is Nothing Then
           With Target
                Select Case Target.Value
                
                    Case (""): .Interior.ColorIndex = 0 'default
                                With Selection.Font
                                     .Name = "Marlett"
                                     .Size = 10
                                End With
                    Case ("h"): .Interior.ColorIndex = 3 'red
                    Case ("hh"): .Interior.ColorIndex = 45 'orange
                    Case ("hhh"): .Interior.ColorIndex = 6 'yellow
                    Case ("hhhh"): .Interior.ColorIndex = 43 'green
                    Case ("hhhhh"): .Interior.ColorIndex = 10 'Dark Green
                    
                End Select
          End With
        End If
    
    ws_exit:
        Application.EnableEvents = True
    End Sub
    
    I wonder if anyone can help me.
    
    Thanks
    Last edited by Annisha; 07-05-2011 at 07:13 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,730

    Re: IF statement with Conditional Formatting.

    Welcome to the forum Annisha. Please take a moment to read the forum rules and add CODE tags to your code example.

    It's often useful to post a sample workbook with some typical data.

    As a pointer, you're changing the value in column A but your case statement is looking at the value in the cell affected by the change in column A. You should modify your Select Case statement to monitor the outcome cell.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-05-2011
    Location
    London, England
    MS-Off Ver
    Excel 2000
    Posts
    3

    Re: IF statement with Conditional Formatting.

    Hi TMShucks,
    
    I would have posted the worksheet as the data need to be protected so I cannot.
    
    I am beginners in Excel VB, I don't seem to understand what you mean by modifying Select Case statement.
    Last edited by Annisha; 07-05-2011 at 07:13 AM.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,730

    Re: IF statement with Conditional Formatting.

    Please add CODE tags to your original post before I can follow this up.

    Regards

  5. #5
    Registered User
    Join Date
    07-05-2011
    Location
    London, England
    MS-Off Ver
    Excel 2000
    Posts
    3

    Re: IF statement with Conditional Formatting.

    I think I have done it correctly now... please let me know if it still hasn't worked.

+ 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