Hey,
I’m quite new to VBA, although I’ve used Excel for years now. I’m currently building up a form of service calculator for a company in Excel, and this time, decided to do it via VBA (for the UI to look smooth with dynamic buttons, and to practice my own VBA). The calculator works as following: Four categories, say A, B, C and D, which each have some given parameters in them.
For example: C has 4 Buttons, each with an own value, which is then added to a running total. A has two buttons, etc.
My problem is, that I’d like for a button to be colored (highlighted) when pressed on, in its corresponding category. So I’d like for A to only have one colored button (if pressed on, otherwise blank), B to only have one colored button, C to only have one colored button and same with D. I’ve used the following code (found from a thread on this forum), but it resets a colored button when pressing on another button in an other category.:
Sub SetColor (v)
Dim cell As String
Dim shp As Shape
cell = Active.Cell.Address
ActiveSheet.Shapes.SelectAll
Selection.ShapeRange.Fill.Forecolor.RGB = RGB(255, 255, 255)
ActiveSheet.Shapes(v).Fill.Forecolor.RGB = RGB(128, 128, 128)
Range(cell).Activate
End Sub
And in each macro to activate the color:
Call SetColor(Application.Caller)
To sum it up, I’m looking for some piece of code (or a modification to the current one), such that when a button is pressed in one category, it stays highlighted when a button is pressed in another category (but if a button is pressed in the same category, the new button is highlighted instead of the old one. I suspect the ’SelectAll’ part in the code is what is causing me the problem, but I’m not sure.
Thank you!
Artiell
I’m quite new to VBA, although I’ve used Excel for years now. I’m currently building up a form of service calculator for a company in Excel, and this time, decided to do it via VBA (for the UI to look smooth with dynamic buttons, and to practice my own VBA). The calculator works as following: Four categories, say A, B, C and D, which each have some given parameters in them.
For example: C has 4 Buttons, each with an own value, which is then added to a running total. A has two buttons, etc.
My problem is, that I’d like for a button to be colored (highlighted) when pressed on, in its corresponding category. So I’d like for A to only have one colored button (if pressed on, otherwise blank), B to only have one colored button, C to only have one colored button and same with D. I’ve used the following code (found from a thread on this forum), but it resets a colored button when pressing on another button in an other category.:
Sub SetColor (v)
Dim cell As String
Dim shp As Shape
cell = Active.Cell.Address
ActiveSheet.Shapes.SelectAll
Selection.ShapeRange.Fill.Forecolor.RGB = RGB(255, 255, 255)
ActiveSheet.Shapes(v).Fill.Forecolor.RGB = RGB(128, 128, 128)
Range(cell).Activate
End Sub
And in each macro to activate the color:
Call SetColor(Application.Caller)
To sum it up, I’m looking for some piece of code (or a modification to the current one), such that when a button is pressed in one category, it stays highlighted when a button is pressed in another category (but if a button is pressed in the same category, the new button is highlighted instead of the old one. I suspect the ’SelectAll’ part in the code is what is causing me the problem, but I’m not sure.
Thank you!
Artiell