I have checkboxes in Userform and depdning on which checkboxes are selected i want to select/activate excel sheets corresponding to the checkboxes.
Ex. Checkbox A, B, C is clicked i want to select/activate tabs A,B,C so i can trasnfer information to those sheets. I know how to trasnfer data but i'm unsure how to select multiple sheets given the condition of checkboxes.
If A_Checkbox.value = True Then
Cells(emptyRow, 1).value=NOD_Text.value
but the problem is i have about 8 checkboxes and i'm unsure how to transfer data into multiple sheets depending on which checkboxes are clicked...
Is there a function where I can say "If any checkboxes values are true then transfer userform data into corresponding sheets?
so i've used the code from the response but i can't seem to get it to work? (i'm not very familiar with vba..sorry...)
Private Sub Add_Button_Click ()
Dim ctrl As Control
Dim emptyRow As Long
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "Checkbox" Then
Transfervalues ctrl, emptyRow
End If
Next
End Sub
Function Transfervalues(cb As MSForms.CheckBox, emptyRow As Long)
Dim ws As Worksheet
If cb Then
Select Case cb.Name
Case "A"
Sheets("A").Cells(emptyRow, 1).Value = NOD_Text.Value
Sheets("A").Cells(emptyRow, 2).Value = TOD_Text.Value
Sheets("A").Cells(emptyRow, 3).Value = Program_Text.Value
Sheets("A").Cells(emptyRow, 4).Value = email_Text.Value
Sheets("A").Cells(emptyRow, 5).Value = OPN_Text.Value
Sheets("A").Cells(emptyRow, 6).Value = CPN_Text.Value
Case "B"
Sheets("B").Cells(emptyRow, 1).Value = NOD_Text.Value
Sheets("B").Cells(emptyRow, 2).Value = TOD_Text.Value
Sheets("B").Cells(emptyRow, 3).Value = Program_Text.Value
Sheets("B").Cells(emptyRow, 4).Value = email_Text.Value
Sheets("B").Cells(emptyRow, 5).Value = OPN_Text.Value
Sheets("B").Cells(emptyRow, 6).Value = CPN_Text.Value
Case "C"
Sheets("C").Cells(emptyRow, 1).Value = NOD_Text.Value
Sheets("C").Cells(emptyRow, 2).Value = TOD_Text.Value
Sheets("C").Cells(emptyRow, 3).Value = Program_Text.Value
Sheets("C").Cells(emptyRow, 4).Value = email_Text.Value
Sheets("C").Cells(emptyRow, 5).Value = OPN_Text.Value
Sheets("C").Cells(emptyRow, 6).Value = CPN_Text.Value
Case "D"
Sheets("D").Cells(emptyRow, 1).Value = NOD_Text.Value
Sheets("D").Cells(emptyRow, 2).Value = TOD_Text.Value
Sheets("D").Cells(emptyRow, 3).Value = Program_Text.Value
Sheets("D").Cells(emptyRow, 4).Value = email_Text.Value
Sheets("D").Cells(emptyRow, 5).Value = OPN_Text.Value
Sheets("D").Cells(emptyRow, 6).Value = CPN_Text.Value
Case "E"
Sheets("E").Cells(emptyRow, 1).Value = NOD_Text.Value
Sheets("E").Cells(emptyRow, 2).Value = TOD_Text.Value
Sheets("E").Cells(emptyRow, 3).Value = Program_Text.Value
Sheets("E").Cells(emptyRow, 4).Value = email_Text.Value
Sheets("E").Cells(emptyRow, 5).Value = OPN_Text.Value
Sheets("E").Cells(emptyRow, 6).Value = CPN_Text.Value
Case "F"
Sheets("F").Cells(emptyRow, 1).Value = NOD_Text.Value
Sheets("F").Cells(emptyRow, 2).Value = TOD_Text.Value
Sheets("F").Cells(emptyRow, 3).Value = Program_Text.Value
Sheets("F").Cells(emptyRow, 4).Value = email_Text.Value
Sheets("F").Cells(emptyRow, 5).Value = OPN_Text.Value
Sheets("F").Cells(emptyRow, 6).Value = CPN_Text.Value
Case "G"
Sheets("G").Cells(emptyRow, 1).Value = NOD_Text.Value
Sheets("G").Cells(emptyRow, 2).Value = TOD_Text.Value
Sheets("G").Cells(emptyRow, 3).Value = Program_Text.Value
Sheets("G").Cells(emptyRow, 4).Value = email_Text.Value
Sheets("G").Cells(emptyRow, 5).Value = OPN_Text.Value
Sheets("G").Cells(emptyRow, 6).Value = CPN_Text.Value
Case "H"
Sheets("H").Cells(emptyRow, 1).Value = NOD_Text.Value
Sheets("H").Cells(emptyRow, 2).Value = TOD_Text.Value
Sheets("H").Cells(emptyRow, 3).Value = Program_Text.Value
Sheets("H").Cells(emptyRow, 4).Value = email_Text.Value
Sheets("H").Cells(emptyRow, 5).Value = OPN_Text.Value
Sheets("H").Cells(emptyRow, 6).Value = CPN_Text.Value
End Select
End If
End Function
Select Case Left(cb.Name, 1)
. Also I will make some revisions to mine based on what you have done. – David Zemens