Using VBA to create multiple color scheme options for worksheets

jmwbowen

Board Regular
Joined
Jul 27, 2012
Messages
58
I have a worksheet containing rectangle shapes being used at buttons. Clicking the shapes points to different macros that change data on another sheet. The macro also changes the color of the shape to indicate that it has been clicked "ON". Clicking the shape again would again change the data on another sheet and color the shape "OFF".

The Shapes Title property is used to reference a named range on the other sheet.

Here's some sample code:

Code:
Set MyShape = ActiveSheet.Shapes(Application.Caller)With MyShape
    Set DataCell = DetectionData.Range(.Title).Offset(DetectionData.Range("DT_RecordNumber").Value, 0)
    
    With .Fill.ForeColor
    If .RGB = RGB(150, 200, 200) Then
        .RGB = RGB(75, 150, 150)
        DataCell.Value = True
    Else
        .RGB = RGB(150, 200, 200)
        DataCell.Value = False
    End If
    End With
End With
Set MyShape = Nothing
Set DataCell = Nothing

The RGB colors are a light and dark blue. However, I'd like to offer the user the option to change the color scheme of the buttons. This would involve 3 different RGB codes, one for the "ON" status, one for the "OFF" status, and one for the Shape border color.

My idea is that a pop-up userform would handle changing the color scheme. Is there some way to create a variable or object or class object (I don't know anything about classes) that would hold the RGB values and then the above could would look something like the following below?

Code:
Set MyShape = ActiveSheet.Shapes(Application.Caller)With MyShape
    Set DataCell = DetectionData.Range(.Title).Offset(DetectionData.Range("DT_RecordNumber").Value, 0)
    
    With .Fill.ForeColor
    If .RGB = ButtonColorOn Then
        .RGB = ButtonColorOff
        DataCell.Value = True
    Else
        .RGB = ButtonColorOn
        DataCell.Value = False
    End If
    End With
End With
Set MyShape = Nothing
Set DataCell = Nothing

The ButtonColorOn and ButtonColorOff objects (variables? class objects?) would hold the RGB values and the userform that changes color schemes would simply change the values inside these objects.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
OP EDIT:

Another thought (again, I don't know much about classes, YET) is creating a class? made up of a Shape object with specific properties working with the RGB values so that code would look something like the following:

Code:
If MyButton.Status = StatusOn Then
     MyButton.Status = StatusOff
     DataCell = False
Else
     MyButton.Status = StatusOn
     DataCell = True
End If

Again, I just don't know how much can be done with RGB values.
 
Upvote 0

Forum statistics

Threads
1,217,376
Messages
6,136,197
Members
449,998
Latest member
jpaul123

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