#Excel #VBA: Conditional Formatting Dynamic Selection
Using VBA driven Conditional Formatting for Dynamic Selection to reduce eye strain and parallax error when analyzing large datasets. The code preserves any existing regular formatting (non-conditional).
Note:
The following code is preferred to be inserted on a particular worksheet. instead of a module.
Also, this code in its current state can be used on a sheet that already does not have conditional formatting since it deletes and applies the 4 conditional rules on each selection change.
The color codes of for cell fill and font for the active selection range and the passive grid guiding range can be customized to desired color.
#Excel: Using #VBA driven #Conditional #Formatting for #Dynamic #Selection to reduce...Ref: https://t.co/pfiV7imRQv pic.twitter.com/BJP5cdDCdE
— Scrip_Tips (@Scrip_Tips) November 13, 2015
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'Macro to dynamically highlight cells to reduce parallax error and eye strain using conditional formatting Dim rng As Variant Cells.FormatConditions.Delete 'To clear any existing conditional formats
'Set the range (active selection) to apply the conditional format with a higher contrast theme to standout Set rng = Target
rng.FormatConditions.Add Type:=xlTextString, String:="*", TextOperator:=xlContains With rng.FormatConditions(1).Interior .ThemeColor = xlThemeColorLight2 .TintAndShade = 0.399975585192419 End With With rng.FormatConditions(1).Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With rng.FormatConditions(1).StopIfTrue = False
rng.FormatConditions.Add Type:=xlTextString, String:="*", TextOperator:=xlDoesNotContain With rng.FormatConditions(2).Interior .ThemeColor = xlThemeColorLight2 .TintAndShade = 0.399975585192419 End With With rng.FormatConditions(2).Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With rng.FormatConditions(2).StopIfTrue = False
'Set the remaining range (passive grid guiders) to apply the conditional format with a lesser contrast theme Set rng = Range(Target.EntireRow.Address & "," & Target.EntireColumn.Address)
rng.FormatConditions.Add Type:=xlTextString, String:="*", TextOperator:=xlContains With rng.FormatConditions(3).Interior .ThemeColor = xlThemeColorLight2 .TintAndShade = 0.799981688894314 End With rng.FormatConditions(3).StopIfTrue = False
rng.FormatConditions.Add Type:=xlTextString, String:="*", TextOperator:=xlDoesNotContain With rng.FormatConditions(4).Interior .ThemeColor = xlThemeColorLight2 .TintAndShade = 0.799981688894314 End With rng.FormatConditions(4).StopIfTrue = False
End Sub












