Automatic Formatting for Cells with Formulas

hamburger

New Member
Joined
Sep 10, 2004
Messages
33
Hi,

Is there a way to automatically make all cells with formulas appear with a chosen background colour?

Thanks!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,

Without VBA, it gets tricky ...


http://www.mrexcel.com/board2/viewtopic.php?t=21312



Otherwise you can use VBA. That might look something like ...


<font face=Tahoma New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)
    <SPAN style="color:#00007F">If</SPAN> Target.HasFormula <SPAN style="color:#00007F">Or</SPAN> Target.HasArray <SPAN style="color:#00007F">Then</SPAN>
        Target.Interior.ColorIndex = 8
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>


HTH
 
Upvote 0
If you want to color all the cells in an existing range that contain formulas, (using VBA), you can do something like this.
Code:
Sub ColorTheFormulas()
For Each cell In Range("A1:E12")
If cell.HasFormula Then
cell.Interior.ColorIndex = 4
End If
Next cell
End Sub
Hope it helps,
Dan
 
Upvote 0
You know, even another one, probably faster ...


<font face=Tahoma New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> ColorSpecialCells()
    <SPAN style="color:#00007F">With</SPAN> Range("A2:E10")
        .SpecialCells(xlCellTypeFormulas, 23).Interior.ColorIndex = 8
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>


I am partial to looping through cells as Dan has, there's always just so much you can do. These should all work though.

(Hey Dan! Howzit!!)
 
Upvote 0
With this UDF:

Code:
Function HasFormula(Cell As Range) As Boolean
    HasFormula = Cell.HasFormula
End Function

You can use a Conditional Formatting formula like:

=HasFormula(A1)
 
Upvote 0
Good Zack. How's things with you?
I think you're right too. The SpecialCells method would be faster. (Noticeably so depending on the amount of data.) Good call.

Dan
 
Upvote 0

Forum statistics

Threads
1,215,518
Messages
6,125,293
Members
449,218
Latest member
Excel Master

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