Dag Gust,
Het staat duidelijk in mijn profiel dat mails zonder uitnodiging zonder reactie blijven.
Dit terzijde, VBA voor voorwaardelijke opmaak is niet zo eenvoudig. Mijn volledige module hieronder.
Ik volg Jan in zijn advies om gewone formules te gebruiken ipv een "zware" omweg via VO.
Option Explicit
Option Private Module
Private mlngPos As Long
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : CFAboveAverage
''' Author © : Jean-Pierre Degroote
''' Date : 05/07/2018
'''---------------------------------------------------------------------------------------
Private Function CFAboveAverage(xloperator As Long) As String
Select Case xloperator
Case 0: CFAboveAverage = "Above Avg"
Case 1: CFAboveAverage = "Below Avg"
Case 2: CFAboveAverage = "Equal or Above Avg"
Case 3: CFAboveAverage = "Equal or Below Avg"
Case 4: CFAboveAverage = "Above Std Dev"
Case 5: CFAboveAverage = "Below Std Dev"
Case Else: CFAboveAverage = "Unknown"
End Select
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : CFDateOperator
''' Author © : Jean-Pierre Degroote
''' Date : 05/07/2018
'''---------------------------------------------------------------------------------------
Private Function CFDateOperator(xloperator As Long) As String
Select Case xloperator
Case 0: CFDateOperator = "Today"
Case 1: CFDateOperator = "Yesterday"
Case 2: CFDateOperator = "Last 7 days"
Case 3: CFDateOperator = "This Week"
Case 4: CFDateOperator = "Last Week"
Case 5: CFDateOperator = "Last Month"
Case 6: CFDateOperator = "Tomorrow"
Case 7: CFDateOperator = "Next Week"
Case 8: CFDateOperator = "Next Month"
Case 9: CFDateOperator = "This Month"
Case Else: CFDateOperator = "Unknown"
End Select
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : CFOperator
''' Author © : Jean-Pierre Degroote
''' Date : 05/07/2018
'''---------------------------------------------------------------------------------------
Private Function CFOperator(xloperator As Long) As String
Select Case xloperator
Case xlBetween: CFOperator = "Between"
Case xlNotBetween: CFOperator = "Not Between"
Case xlEqual: CFOperator = "Equal"
Case xlNotEqual: CFOperator = "Not Equal"
Case xlGreater: CFOperator = "Greater"
Case xlLess: CFOperator = "Less"
Case xlGreaterEqual: CFOperator = "Greater or Equal"
Case xlLessEqual: CFOperator = "Less or Equal"
End Select
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : CFTextOperator
''' Author © : Jean-Pierre Degroote
''' Date : 05/07/2018
'''---------------------------------------------------------------------------------------
Private Function CFTextOperator(xloperator As Long) As String
Select Case xloperator
Case 0: CFTextOperator = "Contains"
Case 1: CFTextOperator = "Does not contain"
Case 2: CFTextOperator = "Begins with"
Case 3: CFTextOperator = "Ends with"
End Select
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : DeleteCFSheet
''' Author © : Jean-Pierre Degroote
''' Date : 05/07/2018
'''---------------------------------------------------------------------------------------
Sub DeleteCFSheet()
If MsgBox(Prompt:="Are you sure?", Buttons:=vbOKCancel + vbCritical + vbDefaultButton2, Title:="Delete conditional formats in sheet.") = vbCancel Then Exit Sub
On Error Resume Next
ActiveSheet.Cells.SpecialCells(xlCellTypeAllFormatConditions).FormatConditions.Delete
On Error GoTo 0
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : DeleteCFWorkbook
''' Author © : Jean-Pierre Degroote
''' Date : 05/07/2018
'''---------------------------------------------------------------------------------------
Sub DeleteCFWorkbook()
Dim objWsh As Worksheet
If MsgBox(Prompt:="Are you sure?", Buttons:=vbOKCancel + vbCritical + vbDefaultButton2, Title:="Delete conditional formats in workbook.") = vbCancel Then Exit Sub
On Error Resume Next
For Each objWsh In ActiveWorkbook.Worksheets
objWsh.Cells.SpecialCells(xlCellTypeAllFormatConditions).FormatConditions.Delete
Next objWsh
On Error GoTo 0
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : FCTypeFromIndex
''' Author © : Jean-Pierre Degroote
''' Date : 30/06/2018
'''---------------------------------------------------------------------------------------
Private 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 13: 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
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : ShowConditionalFormatting
''' Author © : Jean-Pierre Degroote
''' Date : 30/06/2018
'''---------------------------------------------------------------------------------------
Sub ShowConditionalFormatting()
Dim rngCell As Range
Dim lngI As Long
Dim objOutput As Worksheet
Dim objWsh As Worksheet
Dim objSource As Workbook
Dim intArea As Integer
Application.ScreenUpdating = False
Set objSource = ActiveWorkbook
''' Prepare the output
Set objOutput = Workbooks.Add.Worksheets(1)
With objOutput.Cells(1, 1)
.value = "Workbook:"
.Font.size = 14
.Font.Color = 16777215
.Interior.Color = 3506772
End With
With objOutput.Cells(2, 1)
.value = "Date:"
.Font.size = 14
.Font.Color = 16777215
.Interior.Color = 3506772
End With
With objOutput
.Cells(1, 2) = ActiveWorkbook.Name
.Cells(2, 2) = Date
End With
mlngPos = 4
objSource.Activate
For Each objWsh In objSource.Worksheets
Application.StatusBar = "Analysing sheet: " & objWsh.Name
If mlngPos > 4 Then mlngPos = objOutput.Cells(Rows.Count, 2).End(xlUp).Row + 2
With objOutput
.Range(.Cells(mlngPos, 2), .Cells(mlngPos, 8)) = Array("Type", "Range", "StopIfTrue", "Operator", "Formual1", "Formual2", "Color")
.Cells(mlngPos, 1) = objWsh.Name
.Range(.Cells(mlngPos, 1), .Cells(mlngPos, 8)).Font.size = 14
.Range(.Cells(mlngPos, 1), .Cells(mlngPos, 8)).Font.Color = 16777215
.Range(.Cells(mlngPos, 1), .Cells(mlngPos, 8)).Interior.Color = 3506772
End With
objWsh.Activate
On Error Resume Next
lngI = 0
lngI = objWsh.Cells.SpecialCells(xlCellTypeAllFormatConditions).Cells.CountLarge
On Error GoTo 0
If lngI > 0 Then
For intArea = 1 To objWsh.Cells.SpecialCells(xlCellTypeAllFormatConditions).Areas.Count
Set rngCell = objWsh.Cells.SpecialCells(xlCellTypeAllFormatConditions).Areas(intArea)
WriteOutput objOutput, rngCell
Next intArea
Else
Set rngCell = Nothing
WriteOutput objOutput, rngCell
End If
Next objWsh
objOutput.UsedRange.EntireColumn.AutoFit
objOutput.Activate
Set objOutput = Nothing
Set objWsh = Nothing
Set objSource = Nothing
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Name : WriteOutput
''' Author © : Jean-Pierre Degroote
''' Date : 05/07/2018
'''---------------------------------------------------------------------------------------
Sub WriteOutput(objOutput As Worksheet, rngCell As Range)
Dim lngI As Long
mlngPos = objOutput.Cells(Rows.Count, 2).End(xlUp).Row
If objOutput.Cells(mlngPos, 2) = "Type" Then mlngPos = mlngPos + 1
If Not rngCell Is Nothing Then
For lngI = 1 To rngCell.FormatConditions.Count
With objOutput.Cells(mlngPos + lngI, 2)
.value = FCTypeFromIndex(rngCell.FormatConditions(lngI).Type)
.Offset(0, 1).value = rngCell.FormatConditions(lngI).AppliesTo.Address
.Offset(0, 2).value = rngCell.FormatConditions(lngI).StopIfTrue
On Error Resume Next
Select Case rngCell.FormatConditions(lngI).Type
Case 1:
.Offset(0, 3).value = CFOperator(rngCell.FormatConditions(lngI).Operator)
.Offset(0, 4).value = rngCell.FormatConditions(lngI).Formula1
.Offset(0, 5).value = rngCell.FormatConditions(lngI).Formula2
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 2:
.Offset(0, 4).value = "'" & rngCell.FormatConditions(lngI).Formula1
.Offset(0, 5).value = "'" & rngCell.FormatConditions(lngI).Formula2
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 3:
.Offset(0, 4).value = "'" & rngCell.FormatConditions(lngI).ColorScaleCriteria(1).value
.Offset(0, 5).value = "'" & rngCell.FormatConditions(lngI).ColorScaleCriteria(2).value
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).ColorScaleCriteria(1).FormatColor.Color
Case 4:
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).BarColor.Color
Case 5:
.Offset(0, 4).value = rngCell.FormatConditions(lngI).Rank
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 6: ''' no answer yet
Case 7: ''' no answer yet
Case 8:
.Offset(0, 3).value = IIf(rngCell.FormatConditions(lngI).DupeUnique = 0, "Unique", "Duplicates")
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 9:
.Offset(0, 3).value = CFTextOperator(rngCell.FormatConditions(lngI).TextOperator)
.Offset(0, 4).value = Left(Mid(rngCell.FormatConditions(lngI).Formula1, InStr(rngCell.FormatConditions(lngI).Formula1, Chr(34)) + 1), InStr(Mid(rngCell.FormatConditions(lngI).Formula1, InStr(rngCell.FormatConditions(lngI).Formula1, Chr(34)) + 1), Chr(34)) - 1)
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 10:
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 11:
.Offset(0, 3).value = CFDateOperator(rngCell.FormatConditions(lngI).DateOperator)
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 12:
.Offset(0, 3).value = CFAboveAverage(rngCell.FormatConditions(lngI).AboveBelow)
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 13:
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 14:
Case 15:
Case 16:
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case 17:
.Offset(0, 6).Interior.Color = rngCell.FormatConditions(lngI).Interior.Color
Case Else
End Select
On Error GoTo 0
End With
Next lngI
Else
objOutput.Cells(mlngPos + 1, 2) = "No conditional formats in sheet"
End If
End Sub