vba simple Conditional Format IF = to "x" using both TEXT and NUMERIC code?

ChrisOK

Well-known Member
Joined
Mar 26, 2003
Messages
601
Using this simple code to conditionally format cell if "X" is true, can someone share what the most simplistic way is ~ to accomplish this whether it be with NUMERIC or TEXT methods?

IF NEEDING TO CONDITIONALLY FORMAT NUMER:
(THIS CODE WORKS GREAT BUT IS THERE A SHORTER MORE SIMPLISTIC WAY?)
Code:
Sub ColorNmbrIf()
Set test = Range("j2:j50")
For Each cell In test

If IsNumeric(cell.Value) = False Then
cell.Interior.ColorIndex = x1None 'no color

ElseIf cell.Value = "275" Then
cell.Interior.ColorIndex = 3 'red

Else
cell.Interior.ColorIndex = xlNone

End If

Next

End Sub

IF NEEDING TO CONDITIONALLY FORMAT TEXT:
(THIS CODE DOES NOT WORK AND IS THERE A SHORTER MORE SIMPLISTIC WAY?)
Code:
Sub ColorNmbrIf()
Set test = Range("j2:j50")
For Each cell In test

If IsNumeric(cell.Value) = False Then
cell.Interior.ColorIndex = x1None 'no color

ElseIf cell.Value = "Y" Then
cell.Interior.ColorIndex = 3 'red

Else
cell.Interior.ColorIndex = xlNone

End If

Next

End Sub

>>>> Even better, is there a way to write the code in a 'universal way' to accept on the fly changes whether it be NUMERIC or TEXT?
For example, if I'm needing to use a chunk of this code today to locate the number "275" in Column J
and tomorrow I'd like to quickly change the "275" to the letter "Y" to seach cells with the "Y" code in Column R, without having to rewrite code to accept NON-NUMERIC...
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

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