我有一個多方面的問題,關於從VBA表格插入複選框,廣播和下拉值到Excel電子表格中。我正在嘗試在我的代碼中容納幾個案例場景。從VBA表格插入複選框,廣播和下拉值到Excel電子表格
第一套我要插入的項目是一個複選框具有以下名稱/值:
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
如果用戶作出選擇幾個複選框,那麼它應該在的形式1,2,4,5
插入的 - 例如,如果用戶選擇chk_week1, chk_week2, chk_week4 and chk_week5
。
第二組項目我要插入是從無線電基團的單拾取與幀fr_Priority
內followng名稱/值:
Name Value
========== =====
priority_y Yes
priority_n No
因此,如果用戶選擇priority_y
然後Yes
是插入到Excel電子表格中。
我想插入的第三組項目來自三個下拉菜單。這很簡單,但用戶需要在所有三個下拉列表中進行選擇。如果他們對偏好不感興趣,那麼他們選擇'No Preference'
。如果用戶做出這個決定,那麼任何東西都不應該插入到單元中。下列名稱/值都存在:
Name
==========
cbo_fac1
cbo_fac2
cbo_fac3
例如,如果用戶在cbo_fac1選擇的111,222,No Preference
,cbo_fac2,cbo_fac3然後僅被插入。如果選擇111,No Preference,No Preference
,則僅插入111
。
這是我使用的是現在的代碼:
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
感謝這麼多提前!
我想在行中添加項目 – methuselah
然後不是調整大小(totalitems,1),而是調整大小(1,totalitems) –
''rng1.Offset(1,6)= weeks'是代碼段,它是指所有星期必須去的單元格。我如何將它們插入該單元格? – methuselah