I am using the following code to change the forecolor of a pattern:
'Change to Red
Sub Code()
i = ActiveSheet.Shapes.Range(Array(ButtonName)).Fill.BackColor.RGB
Pattern = ActiveSheet.Shapes.Range(Array(ButtonName)).Fill.Pattern
With ActiveSheet.Shapes.Range(Array(ButtonName)).Fill
If i = 255 Then 'If i is red then turn to white
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.BackColor.ObjectThemeColor = msoThemeColorBackground1
.BackColor.TintAndShade = 0
.BackColor.Brightness = 0
.Patterned Pattern
T = 0
'Exit Sub
End If
If i=16777215 Then 'If i is white, turn to blue
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.BackColor.RGB = RGB(0, 176, 240)
.Patterned Pattern
T = 1
Exit Sub
End If
If i=15773696 Then 'If i is blue, turn to red
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.BackColor.RGB = RGB(255, 0, 0)
.Patterned Pattern
T = 2
End If
End With
ActiveSheet.Range("J21").Select
End Sub
These codes work perfectly fine, however, when i try to run it again, the "i" variable doesnt change to the new back color value. Anyone have any idea why?
'Change to Red
Sub Code()
i = ActiveSheet.Shapes.Range(Array(ButtonName)).Fill.BackColor.RGB
Pattern = ActiveSheet.Shapes.Range(Array(ButtonName)).Fill.Pattern
With ActiveSheet.Shapes.Range(Array(ButtonName)).Fill
If i = 255 Then 'If i is red then turn to white
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.BackColor.ObjectThemeColor = msoThemeColorBackground1
.BackColor.TintAndShade = 0
.BackColor.Brightness = 0
.Patterned Pattern
T = 0
'Exit Sub
End If
If i=16777215 Then 'If i is white, turn to blue
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.BackColor.RGB = RGB(0, 176, 240)
.Patterned Pattern
T = 1
Exit Sub
End If
If i=15773696 Then 'If i is blue, turn to red
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.BackColor.RGB = RGB(255, 0, 0)
.Patterned Pattern
T = 2
End If
End With
ActiveSheet.Range("J21").Select
End Sub
These codes work perfectly fine, however, when i try to run it again, the "i" variable doesnt change to the new back color value. Anyone have any idea why?