I have a bit of a multi-faceted question regarding inserting checkbox, radio and dropdown values from a VBA form into the Excel spreadsheet. I am trying to accommodate a couple case scenarios in my code at the moment.
The first set of items I want to insert is a checkbox with the following names/values:
Name Value
========== =====
chk_week1 1
chk_week2 2
chk_week3 3
chk_week4 4
chk_week5 5
chk_week6 6
chk_week7 7
chk_week8 8
chk_week9 9
chk_week10 10
chk_week11 11
chk_week12 12
chk_week13 13
chk_week14 14
chk_week15 15
If the user makes a selection of several checkboxes then it should be inserted in the form 1,2,4,5 - for example if the user selects chk_week1, chk_week2, chk_week4 and chk_week5.
The second set of items I want to insert is a single pick from radio group with the followng names/values within the frame fr_Priority:
Name Value
========== =====
priority_y Yes
priority_n No
So if the user selects priority_y then Yes is inserted into the Excel spreadsheet.
The third set of items I want to insert comes from three drop downs. This is fairly straightforward, but the user is required to make a selection in all three drop downs. If they are not interested in a preference then they select 'No Preference'. If the user makes this decision then nothing should be inserted into cell. The following names/values are present:
Name
==========
cbo_fac1
cbo_fac2
cbo_fac3
For instance if the user makes a selection of 111,222,No Preference in cbo_fac1, cbo_fac2, cbo_fac3 then only 111,222 gets inserted. If 111,No Preference,No Preference is selected then only 111 gets inserted.
This is the code I am using right now:
Private Sub btnSubmit_Click()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = Worksheets("main")
' Copy the data to the database
' Get last empty cell in column A
Set rng1 = ws.Cells(Rows.Count, "a").End(xlUp)
deptCodeSplit = Split(cbo_deptCode.Value, " ")
rng1.Offset(1, 0) = deptCodeSplit(0)
rng1.Offset(1, 1) = cbo_moduleCode.Value
rng1.Offset(1, 2) = cbo_moduleName.Value
rng1.Offset(1, 3) = txt_studentNo.Value
rng1.Offset(1, 4) = cbo_day.Value
rng1.Offset(1, 5) = cbo_period.Value
' rng1.Offset(1, 6) = weeks
rng1.Offset(1, 7) = cbo_weeks.Value
rng1.Offset(1, 8) = cbo_semester.Value
rng1.Offset(1, 9) = cbo_rounds.Value
rng1.Offset(1, 10) = cbo_priority.Value
' rng1.Offset(1, 11) = lectureStyle
rng1.Offset(1, 12) = txt_noRooms.Value
rng1.Offset(1, 13) = cbo_park.Value
' rng1.Offset(1, 14) = fac
' rng1.Offset(1, 15) = pref
rng1.Offset(1, 16) = txt_specialReq.Value
End Sub
Thanks so much in advance!