I have a userform (called Format_Worksheet) that has a combobox control (called Data_Header_Backcolors) that allows the user to make selections that change the background colors of cells in a worksheet (called Dashboard). Currently, the following subroutine handles this, as follows:
While this sub works ok, I recognize there is a lot of redundant code, which makes for a maintenance headache and is making my file larger than it needs to be.
What I would like to do is to pass the .ThemeColor and .TintAndShade values to a subroutine since those are the only things that change in each "case". Please note, however, that for each case there are two different ranges I am colorizing (Range("A2:B5,E2:E5") and Range("C2:D5,F2:H5")), which each have different .ThemeColor and .TintAndShade values.
I've read some books that mention the ability to pass values into a sub as arguments, but I'm not exactly sure how to do it. I'm not quite there yet in my skill level.
Can an expert please lend a hand?
Code:
Public Sub Dashboard_Data_Header_Backcolors()
Select Case Format_Worksheet.Data_Header_Backcolors
Case "White/White"
With Dashboard
.Range("A2:B5,E2:E5").Select
With Selection.Interior
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
.Range("C2:D5,F2:H5").Select
With Selection.Interior
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
.Range("A1").Select
End With
Case "White/Grey"
With Dashboard
.Range("A2:B5,E2:E5").Select
With Selection.Interior
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
.Range("C2:D5,F2:H5").Select
With Selection.Interior
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.249977111117893
End With
.Range("A1").Select
End With
...etc...
End Select
End Sub
What I would like to do is to pass the .ThemeColor and .TintAndShade values to a subroutine since those are the only things that change in each "case". Please note, however, that for each case there are two different ranges I am colorizing (Range("A2:B5,E2:E5") and Range("C2:D5,F2:H5")), which each have different .ThemeColor and .TintAndShade values.
I've read some books that mention the ability to pass values into a sub as arguments, but I'm not exactly sure how to do it. I'm not quite there yet in my skill level.
Can an expert please lend a hand?