stuarto606
New Member
- Joined
- Aug 25, 2023
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Good afternoon,
This is my first post so please bear with me! I work with Excel quite a bit for work but I'm not experienced with VBA other than recording some very basic macros!
I'm building a very simple dashboard and have assigned a button to a macro which changes the colour and texture fill of a shape. it works if I don't add the texture fill (marble) and I can't get it to go back from Marble to Red and I hope someone can help.
It fails on the lines I've highlighted in red.
Here's the code:
Sub MarbleTest()
Dim Pie_1 As Shape
If ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(255, 0, 0) Then
ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(146, 208, 8)
ElseIf ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(146, 208, 8) Then
ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(121, 142, 224)
ElseIf ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(121, 142, 224) Then
ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(255, 192, 0)
ElseIf ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(255, 192, 0) Then
ActiveSheet.Shapes("Pie 1").Fill.PresetTextured msoTextureWhiteMarble
ElseIf ActiveSheet.Shapes("Pie 1").Fill.ForeColor.PresetTextured = (msoTextureWhiteMarble) Then
ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(255, 0, 0)
End If
End Sub
This is my first post so please bear with me! I work with Excel quite a bit for work but I'm not experienced with VBA other than recording some very basic macros!
I'm building a very simple dashboard and have assigned a button to a macro which changes the colour and texture fill of a shape. it works if I don't add the texture fill (marble) and I can't get it to go back from Marble to Red and I hope someone can help.
It fails on the lines I've highlighted in red.
Here's the code:
Sub MarbleTest()
Dim Pie_1 As Shape
If ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(255, 0, 0) Then
ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(146, 208, 8)
ElseIf ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(146, 208, 8) Then
ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(121, 142, 224)
ElseIf ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(121, 142, 224) Then
ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(255, 192, 0)
ElseIf ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(255, 192, 0) Then
ActiveSheet.Shapes("Pie 1").Fill.PresetTextured msoTextureWhiteMarble
ElseIf ActiveSheet.Shapes("Pie 1").Fill.ForeColor.PresetTextured = (msoTextureWhiteMarble) Then
ActiveSheet.Shapes("Pie 1").Fill.ForeColor.RGB = RGB(255, 0, 0)
End If
End Sub