Why isn't my fill cell colour code working?

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

Can you tell me why the first part works fine but the second part doesn't?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 And Target.Row = Range("A" & Rows.Count).End(xlUp).Row Then
    Lr1 = Target.Row
 
'this part works fine
 If Sheets("Training Log").Range("D" & Lr1).Value >= 0.0833 And Sheets("Training Log").Range("D" & Lr1).Value < 0.1249 Then
       Sheets("Training Log").Range("D" & Lr1).Resize(, 1).Interior.Color = RGB(255, 204, 153)
    End If
 
   If Sheets("Training Log").Range("D" & Lr1).Value >= 0.125 And Sheets("Training Log").Range("D" & Lr1).Value < 0.1458 Then
       Sheets("Training Log").Range("D" & Lr1).Resize(, 1).Interior.Color = RGB(191, 191, 191)
    End If
 
   If Sheets("Training Log").Range("D" & Lr1).Value >= 0.1459 And Sheets("Training Log").Range("D" & Lr1).Value < 0.1665 Then
       Sheets("Training Log").Range("D" & Lr1).Resize(, 1).Interior.Color = RGB(255, 204, 0)
    End If
 
   If Sheets("Training Log").Range("D" & Lr1).Value >= 0.1667 Then
       Sheets("Training Log").Range("D" & Lr1).Resize(, 1).Interior.Color = RGB(242, 242, 242)
    End If
 
'this part doesn't (no error but no fill either)
 If Sheets("Training Log").Range("C" & Lr1).Value >= 9.9 And Sheets("Training Log").Range("C" & Lr1).Value < 13.2 Then
       Sheets("Training Log").Range("C" & Lr1).Interior.Color = RGB(255, 204, 153)
    End If
 
  If Sheets("Training Log").Range("C" & Lr1).Value >= 13.2 And Sheets("Training Log").Range("C" & Lr1).Value < 15.1 Then
       Sheets("Training Log").Range("C" & Lr1).Interior.Color = RGB(191, 191, 191)
    End If
 
  If Sheets("Training Log").Range("C" & Lr1).Value >= 15.1 And Sheets("Training Log").Range("C" & Lr1).Value < 17 Then
       Sheets("Training Log").Range("C" & Lr1).Interior.Color = RGB(255, 204, 0)
    End If
 
   If Sheets("Training Log").Range("C" & Lr1).Value >= 17 Then
        Sheets("Training Log").Range("C" & Lr1).Interior.Color = RGB(242, 242, 242)
    End If
 
    End If
End If
I'm guessing it's because the target column is D not C but I don't know how to code it to get both parts to work.

I'd be grateful for some code that will do this.

Many thanks!
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top