Random ThemeColor in sub

Lallo

New Member
Joined
Sep 28, 2010
Messages
44
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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top