Code Changing The Color Property of The Wrong Cells

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,538
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this code:

Code:
If .Range("K" & t) = "AUTO" Then
                .Range("K" & t) = Format(Application.VLookup(.Range("A" & t), rcore, 54, False), "h:mmA/P")
                With .Range("K" & t)
                    .FormatConditions.Delete
                    .Font.Color = vbWhite
                    .Interior.Color = RGB(128, 128, 128)
                End With
             End If
             
             If .Range("L" & t) = "AUTO" Then
                .Range("L" & t) = Format(Application.VLookup(.Range("A" & t), rcore, 57, False), "h:mmA/P")
                With .Range("L" & t)
                    .FormatConditions.Delete
                    .Font.Color = vbWhite
                    .Interior.Color = RGB(128, 128, 128)
                End With
             End If

It is intended to change the font colour to white when the cell = "AUTO". It does, but it also changes the contents of the cell (like NA, and NR) to white when they aren't equal to AUTO.

I'm not sure where I messed up.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
the line:

.Range("K" & t) = Format(...
should update a cell which had AUTO in it to something which probably isn't AUTO. If you want to retain AUTO in the cell, comment-out/delete this line and the similar one below it.
</pre>
 
Upvote 0
Thanks p45cal ... that's what was needed.
Thanks so much for your help.

Jenn
 
Upvote 0

Forum statistics

Threads
1,203,762
Messages
6,057,218
Members
444,914
Latest member
Mamun12345

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