In Excel 2007 VBA:
Is it possible to randomize ThemeColor in a sub?
I have a sub that formats cells that correspond to a certain named range. (here "SV")
What I want is to randomize the ThemeColorAccent number in the code below.
I have 3 more equivalent subs for other named ranges, and I want them to be formatted to different colours. This works fine at the moment, but I want them all to receive random but still disparate colours.
Here's the code (important section in bold):
Sub colour_SV()
'
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ISNUMBER(MATCH(A1,SV,0))"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlPatternLinearGradient
.Gradient.Degree = 45
.Gradient.ColorStops.Clear
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0.5)
.ThemeColor = xlThemeColorAccent2
.TintAndShade = -0.25
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(1)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
Is it possible to randomize ThemeColor in a sub?
I have a sub that formats cells that correspond to a certain named range. (here "SV")
What I want is to randomize the ThemeColorAccent number in the code below.
I have 3 more equivalent subs for other named ranges, and I want them to be formatted to different colours. This works fine at the moment, but I want them all to receive random but still disparate colours.
Here's the code (important section in bold):
Sub colour_SV()
'
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ISNUMBER(MATCH(A1,SV,0))"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlPatternLinearGradient
.Gradient.Degree = 45
.Gradient.ColorStops.Clear
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0.5)
.ThemeColor = xlThemeColorAccent2
.TintAndShade = -0.25
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(1)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub