iT邦幫忙

0

Excel使用VBA下拉式選單疑問

  • 分享至 

  • xImage

如標題的疑問,小弟想要製作一份Excel VBA的巨集,下圖為部門與職務的對應關係,當我部門下拉選單選擇選擇A時,職位的下拉選單則會顯示相對應的職務關係。

https://ithelp.ithome.com.tw/upload/images/20200424/20126631eYRloDPmNK.jpg

https://ithelp.ithome.com.tw/upload/images/20200424/20126631w1vS4v4Ej9.jpg

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
race
iT邦新手 5 級 ‧ 2020-04-26 07:45:21
最佳解答

最近我用Excel表單控制項來寫類似多選的功能,需先用集合套字典來作,再給表單使用
主要資料作一個結構,給程式使用

Public cTool As New Collection
Function coll_data(vOri) As Collection
    Dim irow%, sStaff$, sDepartment$, icol%
    Dim aTool$()
    
    Set coll_data = New Collection
    With coll_data
        .Add CreateObject("scripting.dictionary"), "部門"
        .Add CreateObject("scripting.dictionary"), "人員"
        For icol = 1 To UBound(vOri, 2)
            sDepartment = vOri(1, icol)
            .Item("部門")(sDepartment) = 6 + .Item("部門").Count
            .Add CreateObject("scripting.dictionary"), sDepartment
            For irow = 2 To UBound(vOri)
                sStaff = vOri(irow, icol)
                If Len(sStaff) Then
                    .Item("人員")(sStaff) = 2 + .Item("人員").Count '從2開始計數
                    .Item(sDepartment)(sStaff) = .Item("人員")(sStaff) '記錄所有人的位置
                End If
        Next irow, icol
        aTool = Split("擇一部門 Clear SelectAll 編輯 所有收件人  " & Join(.Item("部門").keys))
        .Add aTool, "fcLB1"
        aTool = Split("編輯模式 新增 刪除/修改 移動 退出編輯 編輯-")
        .Add aTool, "fcLB1_edit"
    End With
End Function
1
海綿寶寶
iT邦大神 1 級 ‧ 2020-04-24 16:24:45

你運氣真好
相同的問題
有人問過了

ccenjor iT邦高手 1 級 ‧ 2020-04-24 19:53:17 檢舉

哇!iflwlyogdgg 運氣真好,您都自動幫他找到答案了。

我要發表回答

立即登入回答