I want to create a code wherein when checkboxes are checked, its caption will be placed into an array and will be separated by comma. For checkboxes 1 to 24 it will be for the column Profits and for Checkboxes 13 to 24 it will be for column Capital. This is the code for where I would like to insert the code for the checkboxes.
Private Sub SUBMIT_Click()
Dim sh As Worksheet, msg As String, arr, c As Range, id
'check for any empty required fields
If Len(TextBox1.Value) = 0 Then msg = msg & vbLf & " - Employee ID"
If Len(msg) > 0 Then 'anything missing?
MsgBox "The following fields are required:" & msg, _
vbOKOnly + vbCritical, "Missing Information"
Else
'OK to write to sheet
Set sh = ThisWorkbook.Sheets("Bulk Loader File")
Set c = sh.Cells(Rows.Count, "A").End(xlUp).Offset(1) '##start adding here
arr = Split(TextBox1.Value, ",") '##split on comma to get an array
For i = 21 To 35 Step 2 '## loop over comboboxes
dataItem = Me.Controls("ComboBox" & i).Value '## read combo values...
schedule = Me.Controls("ComboBox" & (i + 1)).Value
If Len(dataItem) > 0 Then '## any value selected?
For Each id In arr '##loop over the array
c.Resize(1, 30).Value = Array(Trim(id), TextBox2.Value, TextBox3.Value, TextBox4.Value, TextBox5.Value, TextBox6.Value, TextBox7.Value, TextBox8.Value, _
ComboBox7.Value, ComboBox8.Value, ComboBox9.Value, ComboBox10.Value, ComboBox11.Value, _
ComboBox12.Value, ComboBox13.Value, ComboBox14.Value, ComboBox15.Value, ComboBox16.Value, _
ComboBox17.Value, ComboBox1.Value, ComboBox2.Value, ComboBox3.Value, ComboBox4.Value, _
ComboBox5.Value, ComboBox6.Value, ComboBox18.Value, ComboBox19.Value, ComboBox20.Value, dataItem, schedule, Profits, Capital)
Set c = c.Offset(1) '##next output row
Next id
End If
Next i
MsgBox "Information Loaded", vbOKOnly + vbInformation, "Notification"
Unload Me
End If
End Sub
This is my draft code for checkboxes, but I am not sure if this is correct and if how will it be placed in my current code.
Private Sub CommandButton1_Click()
Dim sh As Worksheet, arr, c As Range, id
Set sh = ThisWorkbook.Sheets("Bulk Loader File")
Set c = sh.Cells(Rows.Count, "A").End(xlUp).Offset(1) '##start adding here
For Each xcontrol In Me.Controls
If TypeName(xcontrol) = "CheckBox" And xcontrol.Value = True Then
CheckBox.Value = CheckBox.Caption
arr = Split(CheckBox.Value, ",")
For i = 1 To 24 Step 2
Profits = Me.Controls("Checkbox" & i).Value
Capital = Me.Controls("Checkbox" & (i + 1)).Value