C
Colleyville Alan
I recently became aware of the possibility of using conditional formatting
to highlight the cells in a spreadsheet which contain formulas. This uses
the GET.CELL method from XML. While it cannot reference another workbook
(like Personal.xls), I have still been able to write a macro in my
Personal.xls folder that sets the name range and conditional references in
the active workbook; while I "wrote" it, I heavily borrowed from others
posts on a website The function and sub below toggle this conditional
formatting for the entire worksheet.
Question: how do I set this up so that only a selected range has the
formatting change? I do not understand the Get.Cell command or syntax and
have yet to find an explanation of it. I do not actually know what it is
doing other than it does make the cells with formulas change their fill
color. Can someone explain how to change only a selected range and how the
Get.Cell command works (or a link)?
Thanks much.
Sub DisplayFormulas()
ScreenUpdating = False
If NameExists("DisplayFormula") = False Then
ActiveWorkbook.Names.Add Name:="DisplayFormula", RefersToR1C1:= _
"=GET.CELL(48,INDIRECT(""rc"",FALSE))"
Cells.Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=DisplayFormula"
Selection.FormatConditions(1).Interior.ColorIndex = 34
Range("A1").Select
Else
ActiveWorkbook.Names("DisplayFormula").Delete
End If
Range("A1").Select
ScreenUpdating = True
End Sub
Function NameExists(TheName As String) As Boolean
On Error Resume Next
NameExists = Len(ActiveWorkbook.Names(TheName).Name) <> 0
NameExists = Len(ActiveWorkbook.Names("DisplayFormula").Name) <> 0
End Function
to highlight the cells in a spreadsheet which contain formulas. This uses
the GET.CELL method from XML. While it cannot reference another workbook
(like Personal.xls), I have still been able to write a macro in my
Personal.xls folder that sets the name range and conditional references in
the active workbook; while I "wrote" it, I heavily borrowed from others
posts on a website The function and sub below toggle this conditional
formatting for the entire worksheet.
Question: how do I set this up so that only a selected range has the
formatting change? I do not understand the Get.Cell command or syntax and
have yet to find an explanation of it. I do not actually know what it is
doing other than it does make the cells with formulas change their fill
color. Can someone explain how to change only a selected range and how the
Get.Cell command works (or a link)?
Thanks much.
Sub DisplayFormulas()
ScreenUpdating = False
If NameExists("DisplayFormula") = False Then
ActiveWorkbook.Names.Add Name:="DisplayFormula", RefersToR1C1:= _
"=GET.CELL(48,INDIRECT(""rc"",FALSE))"
Cells.Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=DisplayFormula"
Selection.FormatConditions(1).Interior.ColorIndex = 34
Range("A1").Select
Else
ActiveWorkbook.Names("DisplayFormula").Delete
End If
Range("A1").Select
ScreenUpdating = True
End Sub
Function NameExists(TheName As String) As Boolean
On Error Resume Next
NameExists = Len(ActiveWorkbook.Names(TheName).Name) <> 0
NameExists = Len(ActiveWorkbook.Names("DisplayFormula").Name) <> 0
End Function