VBA Code

Sakuji

New Member
Joined
May 2, 2004
Messages
32
I was kindly given some code to help me with a spreadsheet and now I would like to add to it. When I input data like "LTS" I would like the cell to colour as indicated in the code but I need the font to be white. What do I need to add to the following code to achieve this?

If Target.value="LTS" then
Target.interior.colorindex=3
end if

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
And you might want to have an Else in there to set it back if it is not LTS, something like:

Code:
If Target.Value = "LTS" Then
    Application.EnableEvents = False
    Target.Interior.ColorIndex = 3
    Target.Font.Color = vbWhite
    Application.EnableEvents = True
Else
    Application.EnableEvents = False
    Target.Interior.ColorIndex = xlNone
    Target.Font.Color = vbBlack
    Application.EnableEvents = True
End If
 

Forum statistics

Threads
1,147,694
Messages
5,742,671
Members
423,746
Latest member
Joaogomes

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
Top