SensualCarrots
New Member
- Joined
- Mar 21, 2015
- Messages
- 46
I'm wondering if anyone can help me consolidate this. I have 59 checkboxes on a worksheet. They are all ActiveX controls that run the following code. Each is unique. The purpose is if the box is unchecked, it unlocks the sheet, and changes the Locked property of an adjacent cell to Unlocked. If the box is checked, it locks the adjacent cell, and places a formula in that cell based on the row. The problem is that I have the following code in my sheet object 59 times. I was hoping there is a way to do this with an array or something else. The Checkboxes are all labeled as CheckBox1 - CheckBox59. CheckBox1 is in Cell A7, CheckBox 59 is in cell A65.
I did have this consolidated in an earlier version, but used a scripting library to check the value of each cell in a range, then populated the results based on each cells value (True/False). This worked, but took 3-5 seconds to process each time a box was checked/unchecked. If this is the only way, the speed of the new method outweighs the 59 separate subs.
I did have this consolidated in an earlier version, but used a scripting library to check the value of each cell in a range, then populated the results based on each cells value (True/False). This worked, but took 3-5 seconds to process each time a box was checked/unchecked. If this is the only way, the speed of the new method outweighs the 59 separate subs.
Code:
Private Sub CheckBox55_Click()
Dim C As Range
Set C = Range("C61")
ActiveSheet.Unprotect "password"
If CheckBox55.Value = False Then
C.Formula = "=M" & C.Row
C.FormulaHidden = True
C.Locked = True
C.Offset(0, 1).Select
Else
If C.Value = "" Or C.Formula = "=M" & C.Row Then
C.FormulaHidden = False
C.Locked = False
C.Value = ""
C.Select
End If
End If
If ActiveSheet.Range("D28") = "Unlock" Then Exit Sub Else
ActiveSheet.Protect "password"
End Sub
Last edited: