Luke M
New Member
- Joined
- Mar 6, 2014
- Messages
- 4
Hey everyone,
I've been scouring forums and tutorials looking for the answer, but I have yet to find it. I have created an array that I assign the starting and ending cell values to when the user selects a checkbox (I used the checkbox changed event). The problem I'm having is with passing the array by reference into the function. I know that the code works without the array, but I need to clean it up so I'm not copy/pasting 20 lines of code for each checkbox changed event. Any help y'all can provide is much appreciated.
The purpose of coding the check boxes is to fill the back color of the row with green to signify it has been completed. This makes scanning the lists visually much faster.
I'm using windows 8.1 and excel 2013
I've been scouring forums and tutorials looking for the answer, but I have yet to find it. I have created an array that I assign the starting and ending cell values to when the user selects a checkbox (I used the checkbox changed event). The problem I'm having is with passing the array by reference into the function. I know that the code works without the array, but I need to clean it up so I'm not copy/pasting 20 lines of code for each checkbox changed event. Any help y'all can provide is much appreciated.
The purpose of coding the check boxes is to fill the back color of the row with green to signify it has been completed. This makes scanning the lists visually much faster.
I'm using windows 8.1 and excel 2013
Code:
' Array for passing cell values to the function
Dim cbxArray(1 To 2) As String
' Checbox changed event for worksheet
Private Sub CheckBox1_Change()
cbxArray(1) = B3
cbxArray(2) = G3
If CheckBox1.Value = True Then
Change_Row_Color (cbxArray())
Else
Remove_Row_Color (cbxArray())
End Sub
' Function to change the color of the row when checkbox is selected
' Note: the code inside the function is generated via the excel macro recorder
Public Function Change_Row_Color(arr1 As String) As Integer
Range("Cell & arr1(1):Cell & arr1(2)").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Function
' Function to remove any row color when the checkbox is deselected
Public Function Remove_Row_Color(arr2 As String) As String
Range("Cell & arr2(1):Cell & arr2(2)").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Function
Last edited: