Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Highlighting All Formula Cells

5 views
Skip to first unread message

max

unread,
Nov 7, 2001, 11:14:06 PM11/7/01
to
Hi group,

Would like to consult you. For user training purposes, I
need all formula cells in a workbook to be highlighted, to
differentiate these from data cells. It is very tedious
to do this manually.

Is there a vba sub available which can detect & auto-
colour (as a highlight) all formula cells in a workbook ?

TIA
max

Gary Brown

unread,
Nov 7, 2001, 11:27:52 PM11/7/01
to
Max,
Here's an example, Hope it helps,
Gary L. Brown
Kinneson Consulting
Gary....@Kinneson.com
www.Kinneson.com

'/============================/
Sub ColorFormulas()
ActiveCell.SpecialCells(xlCellTypeFormulas).Select
'yellow background
Selection.Interior.ColorIndex = 36
'red letters
Selection.Font.ColorIndex = 3
End Sub
'/============================/


"max" <demec...@yahoo.com> wrote in message
news:5df401c1680b$cef7cd80$36ef2ecf@tkmsftngxa12...

Debra Dalgleish

unread,
Nov 7, 2001, 11:38:47 PM11/7/01
to
You can record a macro as you do the following:
1. Select all the cells
2. Choose Edit>Go To
3. Click Special
4. Select Formuala, click OK
5. Select a Fill Colour.
6. Stop the recorder.

The resulting code can be trimmed:

Sub HighlightFormula()
Cells.SpecialCells(xlCellTypeFormulas, 23) _
.Interior.ColorIndex = 6
End Sub

max

unread,
Nov 8, 2001, 2:23:51 AM11/8/01
to
Thanks, Debra. It works great ! As I want the highlight to
be for the workbook (ie all worksheets), I tried macro-
recording the selection of all worksheets, and came up
with the following (for my test workbook):

Sheets(Array("Sheet1 (2)", "Sheet1")).Select
Sheets("Sheet1 (2)").Activate

How do I modify the above macro so that it will auto-run
your sub for all open worksheets in any workbook ?

Thanks
max

>.
>

max

unread,
Nov 8, 2001, 2:26:31 AM11/8/01
to
Thanks, Gary. Your sub works great !

As I want the highlight to be for the workbook (ie all

worksheets), what needs to be added so that the sub will
auto-run for all open worksheets in any workbook ?

cheers
max

>.
>

Roger Govier

unread,
Nov 8, 2001, 6:11:03 AM11/8/01
to
Hi Max

Adapting Debra's formula, put this into the code area for This Workbook

Private Sub Workbook_Open()
Dim s As Worksheet
For Each s In ActiveWorkbook.Worksheets
s.Cells.SpecialCells(xlCellTypeFormulas, 23) _
.Interior.ColorIndex = 6
Next s
End Sub


--
Regards

Roger Govier
Technology 4 U


"max" <demec...@yahoo.com> wrote in message

news:7e0601c16826$50bc53d0$b1e62ecf@tkmsftngxa04...

Dana DeLouis

unread,
Nov 8, 2001, 9:26:37 AM11/8/01
to
Just to mention... the '23' is the sum of all options to xlCellTypeFormulas.
This is the default setting.
Adapting Debra's formula, you may want to add an "On Error" just in case
there are no formulas.

Sub HighlightFormula()
'In case there are no formulas.
On Error Resume Next
Cells.SpecialCells(xlFormulas).Interior.ColorIndex = 6
End Sub

--
Dana DeLouis Windows Me & Office XP

"Roger Govier" <Roger....@btinternet.com> wrote in message
news:O2gqYbEaBHA.880@tkmsftngp02...

max

unread,
Nov 8, 2001, 10:11:31 AM11/8/01
to
Thanks, Roger & Dana. Yes, the amended sub works fine.
Much appreciated.

cheers
max

>.
>

Ian Brown FCA

unread,
Nov 9, 2001, 9:04:12 AM11/9/01
to
Max,

Here's a way to do it without using VBA!
Select cell A1 on any sheet in the workbook
Define the name CellHasFormula (using Insert | Name | Define) as
=GET.CELL(48,!A1)

In Format | Conditional Formatting use a "Formula Is" setting of
=CellHasFormula
to trigger the defined formats.

Apply the conditional formatting as required

HTH

Ian

"max" <demec...@yahoo.com> wrote in message

news:5df401c1680b$cef7cd80$36ef2ecf@tkmsftngxa12...

Roger Govier

unread,
Nov 9, 2001, 9:31:26 AM11/9/01
to
Hi Ian

Very neat solution

--
Regards

Roger Govier
Technology 4 U

"Ian Brown FCA" <bro...@globalnet.co.uk> wrote in message
news:tunoh45...@corp.supernews.com...

max

unread,
Nov 9, 2001, 6:54:47 PM11/9/01
to
Thanks, Ian !
cheers
max

>.
>

Harlan Grove

unread,
Nov 12, 2001, 4:44:49 PM11/12/01
to
Ian Brown FCA <bro...@globalnet.co.uk> wrote...
...

>Here's a way to do it without using VBA!
>Select cell A1 on any sheet in the workbook
>Define the name CellHasFormula (using Insert | Name | Define) as
>=GET.CELL(48,!A1)
>
>In Format | Conditional Formatting use a "Formula Is" setting of
>=CellHasFormula
>to trigger the defined formats.
>
>Apply the conditional formatting as required

WARNING - THIS IS DANGEROUS!

In Excel 97 and 2K, if the cell so formatted or a cell with a formula
referring to CellHasFormula were copied then pasted into a different
worksheet, Excel will CRASH, as in TOTAL DATA LOSS since last save. Try it
for yourself.

I believe this was fixed in XP, but the XLM formula in defined name trick
should always carry a warning.


max

unread,
Nov 14, 2001, 8:39:56 AM11/14/01
to
Thanks for the alert, Harlan !
Have noted it since I'm using XL97.
cheers.

>-----Original Message-----
>Ian Brown FCA <bro...@globalnet.co.uk> wrote...

>....

>.
>

0 new messages