简体   繁体   中英

Array values are not being added to combobox in VBA

Hi all this is my first question. I'm trying to populate my combobox (named "ComboBox1") in my userform. However, I'm having trouble getting this simple task accomplished. Here's my code:

Private Sub Form_Load(menu)
    Dim i As Integer

    For i = 0 To 28
        Me.ComboBox1.AddItem menu(i, 0, 0)
    Next i
End Sub

menu is a 3d array where menu((0 to 28), 0 ,0) are strings of dates in April. However, vba isn't adding them into my combo box. Could anyone should some light on this matter?

That is most probably because you are not calling the Form_Load(menu)

This works for me.

Dim menu(0 To 28, 0, 0)
Dim i As Long

Private Sub CommandButton1_Click()
    For i = 0 To 28
        menu(i, 0, 0) = "Sid" & (i + 1)
    Next i

    Form_Load menu
End Sub

Private Sub Form_Load(menu)
    For i = 0 To 28
        Me.ComboBox1.AddItem menu(i, 0, 0)
    Next i
End Sub

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM