+ Reply to Thread
Results 1 to 4 of 4

Change Event problem

Hybrid View

  1. #1
    Registered User
    Join Date
    10-10-2007
    Posts
    22

    Change Event problem

    Hello
    I was wondering if someone can tell me what’s wrong with this Change event code? I’m trying to change the colour of a range of cells C40:F50 based on the content of cell F40. Example, if the cell(F40) contains “CNX” the range of cells turns red. If the cell(F40) contain “Proposed” the range of cell turn yellow. I can’t get this to work.

    Thanks in Advance

     Private Sub Worksheet_Change(ByVal Target As Range)
    
      If Target.Row = 1 Then Exit Sub
      If Target.Range = Range("F40") Then
           Application.EnableEvents = False
      Select Case LCase(Target.Value)
         Case "CNX"
            Target.Range("C40:F50").Interior.ColorIndex = 3
         Case "PROPOSED"
            Target.Range("C40:F50").Interior.ColorIndex = 40
         Case Else
            Target.Range("C40:F50").Interior.ColorIndex = xlColorIndexAutomatic
      End Select
      Application.EnableEvents = True
    End Sub

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Try
     Private Sub Worksheet_Change(ByVal Target As Range)
    
      If Target.Row = 1 Then Exit Sub
      If Target.Address = "$F$40" Then
      Application.EnableEvents = False
      Select Case UCase(Target.Value)
         Case "CNX"
            Range("C40:F50").Interior.ColorIndex = 3
         Case "PROPOSED"
            Range("C40:F50").Interior.ColorIndex = 40
         Case Else
            Range("C40:F50").Interior.ColorIndex = xlColorIndexAutomatic
      End Select
      Application.EnableEvents = True
      End If
    End Sub

  3. #3
    Registered User
    Join Date
    10-10-2007
    Posts
    22
    Hi Big Bas,
    Tried the new code but still no joy....It all seems to make sense but it just won't change the colour of the cells.
    Thanks for trying
    Glenness

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Glen, I tested the code, and it worked for me. Copy and paste my code exactly into your sheet code. If it still doesn't work, post a .zip of your file and we can make it work.

    Note: One of the reasons your code doesn't work was because of this line:
    Select Case LCase(Target.Value)
    Basically, that code takes the lowercase of the value in TARGET. However, when you look at the CASES in your select case structure, you will note that all of the entries are upper case. To correct this, change that line of code to:
    Select Case UCase(Target.Value)

+ 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