Hi,
First post! I'm new to Excel VBA and have created a simple macro using a checkbox that will color a selected range within a row. However, the macro requires a specific address range to change the color of the cells. Is there a to cause the coloring effect on other address ranges using other checkboxes without having to duplicate the macro and changing the address range to another specific address range? If I end up having several hundred rows, each served by a checkbox, do I have to have a separate macro for each checkbox? Seems to me that I should be able to designate a checkbox to control a specific range using a single macro that can accept different ranges. That is, if I click on a specific checkbox, the macro should be able to determine which address range to color.
Below is the macro, but is for a single address range:
Sub Set_Row_color()
'
If Range("B5") = "True" Then //here the cell is selected for the
TRUE/FALSE
Range("A5:F5").Select //This is range to color
With Selection.Interior
.ColorIndex = 14
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Else
Range("A5:I5").Select
Selection.Interior.ColorIndex = xlNone //this removes the color when
the checkbox is unchecked.
End If
End Sub
If I want to place another checkbox on the next row, how can I use this same macro without having to rewrite it using B6 for the T/F of checkbox and
A6:F6 for colored range/
Thanks,
Dave Rogers
Bookmarks