Conditional format - if cell contains part of formula

Formula11

Active Member
Joined
Mar 1, 2005
Messages
440
Office Version
  1. 365
Platform
  1. Windows
Is it possible to carry out a conditional format for cells that contain part of a formula.
Specifically I want to format cells that have "+2" in their formula, for example "=7+2" will be formatted.
I was thinking to convert to text and then scan for the "+2", but don't know how to do this.
So far I have only a generic format for all formulas.

VBA Code:
=ISFORMULA(A1)=TRUE
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,

What if the cell formula is "=7+21"?

Look into FORMULATEXT function:

Book3.xlsx
A
19
210
Sheet974
Cell Formulas
RangeFormula
A1A1=7+2
A2A2=7+3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:A2Expression=FIND("+2",FORMULATEXT(A1))textNO
 
Upvote 0
Thanks, I was going to use SEARCH or FIND, not sure of the difference.
The FORMULATEXT function helps a lot.
This is getting somewhere, I don't know if correct or not.
It doesn't account for "=7+21" though.


VBA Code:
=SEARCH("+2",FORMULATEXT(A1))
 
Upvote 0
OK thanks for the suggestion.
This seems to work.

VBA Code:
=SEARCH("+2",RIGHT(FORMULATEXT(A1), 2))
 
Upvote 0
You're welcome, if the "+2" is always at the End of the subject formula cell, you don't need SEARCH or FIND:

BTW, difference between, SEARCH is Not case sensitive, whereas FIND is case sensitive.

Book3.xlsx
A
19
210
328
Sheet974
Cell Formulas
RangeFormula
A1A1=7+2
A2A2=7+3
A3A3=7+21
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:A3Expression=RIGHT(FORMULATEXT(A1),2)="+2"textNO
 
Upvote 0
Solution
You're very welcome, thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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