Hi guys,
I posted this question on another forum yesterday, but to no avail and zero replies.
I have developed a UserForm where one can manually click to turn "on" lighting zones and double-click to turn "off" the zones. The zones are simply labels and this is done by changing the BackColor of the labels (zones).
I have it all working as intended, you can see the code below for single-clicking on the labels:
Private Sub Label1_Click()
Me.Label1.BackColor = RGB(51, 102, 255)
End Sub
Private Sub Label2_Click()
Me.Label2.BackColor = RGB(51, 102, 255)
End Sub
.
.
.
Private Sub Label50_Click()
Me.Label50.BackColor = RGB(51, 102, 255)
End Sub
Here is the code for double-clicking on the labels:
Private Sub Label1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.Label1.BackColor = RGB(79, 79, 79)
End Sub
Private Sub Label2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.Label2.BackColor = RGB(79, 79, 79)
End Sub
.
.
.
Private Sub Label50_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.Label50.BackColor = RGB(79, 79, 79)
End Sub
As you can see here, I have a crazy amount of written code! I am sure there is some way to shorten this code so it is easier to make changes in the future. Perhaps a loop of sorts? The issue I have is that since each is a different subroutine, I am not sure how that can be done.
Can anyone help me by showing me how I can write some code for Labels 1 to 50 and have it loop, instead of copying and pasting fifty times?
Any help would be appreciated! Thanks guys.
Bookmarks