View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Show cells with formulas without permanently changing the cells

This doesn't incorporate your flag so adjust if you need that.

Select either a single cell to get formulas in whole sheet or a selection of
cells.

Sub ToggleFormulaColour()
Dim rng As Range, vFntClrIdx

On Error Resume Next
Set rng = Selection.SpecialCells(xlCellTypeFormulas, 23)
On Error GoTo errH
If rng Is Nothing Then
MsgBox "No Formulas"
Else

vFntClrIdx = rng.Font.ColorIndex
If IsNull(vFntClrIdx) Then vFntClrIdx = -1

If vFntClrIdx 0 Then
vFntClrIdx = xlAutomatic
Else
vFntClrIdx = 5 'blue in a default palette
End If

rng.Font.ColorIndex = vFntClrIdx
End If

errH:

End Sub

Note SpecialCells in VBA fails if a little over 8000 discontiguous areas are
involved.

Also try Ctrl-`¬¦ the key under Esc.

Regards,
Peter T


"DoctorG" wrote in message
...
I want to create an On/Off button that will temporarily show which cells
contain formulas.

If someone knows a better way pls say so.

I thought of adding and then subtracting a fixed number from the
Interior.color property but I don't know how to retrieve the current

value.

rngFormulas.Select
If flag = False Then
With Selection.Interior
.ColorIndex = ????? + 300000
End With
flag = True
Else
With Selection.Interior
.ColorIndex = ????? - 300000
End With
flag = False
End If