gingerafro
Active Member
- Joined
- Mar 23, 2005
- Messages
- 448
I have a worksheet event macro that performs a conditional format on certain data fields in a pivot table.
However, if a user removes the field, the macro errors because it doesn't exist.
What I need is a 'if the field isn't there, skip this bit of code'
The current code is:
However, if a user removes the field, the macro errors because it doesn't exist.
What I need is a 'if the field isn't there, skip this bit of code'
The current code is:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Cells.Select
Selection.FormatConditions.Delete
ActiveSheet.PivotTables("PivotTable1").PivotSelect "AVAILABILITY", _
xlDataAndLabel, True
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="0"
Selection.FormatConditions(1).Interior.ColorIndex = 3
ActiveSheet.PivotTables("PivotTable1").PivotSelect "% AVAILABLE", _
xlDataAndLabel, True
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="0.0002", Formula2:="0.4"
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="0.4001", Formula2:="0.7"
Selection.FormatConditions(2).Interior.ColorIndex = 6
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="0.0001"
Selection.FormatConditions(3).Font.ColorIndex = 2
Range("A1").Select
End Sub