VBA and condition formating

mduntley

Board Regular
Joined
May 23, 2015
Messages
139
Office Version
  1. 365
Platform
  1. Windows
Tried to do a google search, but unable to find it. I need to get a way to get the current cell is active to apply a condition formating. It change all of the time so it is not a Set location.

My condition formatting

If current cell has the word NOT in it to change the cell into the red.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
If you do not have any other Worksheet_Change or Worksheet-SelectionChangePrivate event code in the sheet code module then you could use the code below to do what you want. It is unclear whether you want it to apply as changes are made or if you want it to apply for existing data in a cell, so the two even codes below will cover either instance.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
    If InStr(UCase(Target.Value), "NOT") > 0 Then
        Target.Interior.Color = vbRed
    End If
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
    If InStr(UCase(Target.Value), "NOT") > 0 Then
        Target.Interior.Color = vbRed
    End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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