Basically, I have code, that looks at a "schedule" sheet for a list of team members names. It creates two sheets per member and then creates a checkbox on my "Report Builder" sheet (my main action screen). There are also some backwards checks, but that is also working fine. This list will expand or contract depending on adding or removing team members in the "schedule" tab. Warning: I am not a VBA expert, I only play around when inspired. The code below works for creating the checkboxes and tabs:
Sub ActX_Add_Multiple_CheckBox()
'Disable Screen Update
Application.ScreenUpdating = False
'Variable Declaration
Dim Rng As Range
Dim ShtRng As Range
Dim WrkSht As Worksheet
Dim RenChk As Object
Sheets("Schedule").Select
Range("c11").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Report Builder").Select
Range("k1").Select
ActiveSheet.Range("K1").EntireColumn.PasteSpecial Paste:=xlPasteValues
Columns("k:k").Sort key1:=Range("k1"), order1:=xlAscending, Header:=xlNo
Range("k1").Select
Set ShtRng = Range(Selection, Selection.End(xlDown))
Set WrkSht = Application.ActiveSheet
For Each Rng In ShtRng
Set RenChk = Sheets("Report Builder").OLEObjects.Add("Forms.CheckBox.1", Left:=Rng.Left, Top:=Rng.Top, Width:=150, Height:=Rng.Height)
RenChk.Object.Caption = Rng
Rng.ClearContents
Next
'Enable Screen Update
Application.ScreenUpdating = True
End Sub
I need this to build these click events, and i would like to have it loop through instead of me writing each click event separately, manually:
Private Sub CheckBox1_Click()
Dim cbName As String
cbName = CheckBox1.Caption
If CheckBox1.Value = True Then
Sheets(cbName & " TS").Visible = True
Sheets(cbName & " TS (EDIT)").Visible = True
Else
Sheets(cbName & " TS").Visible = False
Sheets(cbName & " TS (EDIT)").Visible = False
End If
End Sub
Any suggestions would be helpful (First time poster here)