ReignEternal
New Member
- Joined
- Apr 11, 2021
- Messages
- 41
- Office Version
- 365
- Platform
- Windows
Hello,
I have a situation where I am trying to list all conditional formatting rules that are in an entire workbook. In this forum I was able to find a thread that is over 3400 days old. Thread is titled "List all conditional formatting rules in a worksheet". In that thread, this is the VBA
I have tested it and it only does a single worksheet and it only works on that one worksheet. Im looking to find all conditional formatting in the entire workbook and in the results, tell me which worksheet the CF lives on
I have a situation where I am trying to list all conditional formatting rules that are in an entire workbook. In this forum I was able to find a thread that is over 3400 days old. Thread is titled "List all conditional formatting rules in a worksheet". In that thread, this is the VBA
VBA Code:
Function FCTypeFromIndex(lIndex As Long) As String
Select Case lIndex
Case 12: FCTypeFromIndex = "Above Average"
Case 10: FCTypeFromIndex = "Blanks"
Case 1: FCTypeFromIndex = "Cell Value"
Case 3: FCTypeFromIndex = "Color Scale"
Case 4: FCTypeFromIndex = "DataBar"
Case 16: FCTypeFromIndex = "Errors"
Case 2: FCTypeFromIndex = "Expression"
Case 6: FCTypeFromIndex = "Icon Sets"
Case 14: FCTypeFromIndex = "No Blanks"
Case 17: FCTypeFromIndex = "No Errors"
Case 9: FCTypeFromIndex = "Text"
Case 11: FCTypeFromIndex = "Time Period"
Case 5: FCTypeFromIndex = "Top 10?"
Case 8: FCTypeFromIndex = "Unique Values"
Case Else: FCTypeFromIndex = "Unknown"
End Select
End Function
Sub ShowConditionalFormatting()
Dim cf As Variant
Dim rCell As Range
Dim colFormats As Collection
Dim i As Long
Dim wsOutput As Worksheet
Set colFormats = New Collection
For Each rCell In Worksheets("Fin Stmt").Cells.SpecialCells(xlCellTypeAllFormatConditions).Cells
For i = 1 To rCell.FormatConditions.Count
On Error Resume Next
colFormats.Add rCell.FormatConditions.Item(i), rCell.FormatConditions(i).AppliesTo.Address
On Error GoTo 0
Next i
Next rCell
Set wsOutput = Workbooks.Add.Worksheets(1)
wsOutput.Range("A1:E1").Value = Array("Type", "Applies To", "StopIfTrue", "Formual1", "Worksheet")
For i = 1 To colFormats.Count
Set cf = colFormats(i)
With wsOutput.Cells(i + 1, 1)
.Value = FCTypeFromIndex(cf.Type)
.Offset(0, 1).Value = cf.AppliesTo.Address
.Offset(0, 2).Value = cf.StopIfTrue
.Offset(0, 4).Value = cf.ThisWorksheet
On Error Resume Next
.Offset(0, 3).Value = "'" & cf.Formula1
On Error GoTo 0
End With
Next i
wsOutput.UsedRange.EntireColumn.AutoFit
End Sub
I have tested it and it only does a single worksheet and it only works on that one worksheet. Im looking to find all conditional formatting in the entire workbook and in the results, tell me which worksheet the CF lives on