• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

VBA Strings and Arrays

I have an array A(10) which I want to control using a combobox but can not get it to work

for i = 0 to unbound(combobox1,value) .... I need this loop to run when the user select A from the drop down

Cheers
0
borris111698
Asked:
borris111698
  • 2
1 Solution
 
mcdown75Commented:
Try this

dim i as integer
For i = 0 to upperbound(A)
    myComboBox.additem(a(i))
Next
myCombo.index = 0

This should loop through your array and add each item to your combo box.
0
 
borris111698Author Commented:
Cheers Mcdown but I already have a 2 column dropdown (combobox1) populated from an array Section(), the 1st Column has letters A-N the second a description. When the user selects an item I want to populate a sub 2 column dropdown (combobox2) from the arrays A(5), B(6), C(7), D(8)...... etc

I have been able to this using select case, but thought I could do it more simply by using

for i = 0 to unbound(combobox1.value)

therefore if the user selects B from the first dropdown the second in populated with 7 items from the array..
0
 
GrahamSkanCommented:
Are you saying that the letters A to N are the names of 14 arrays and that you need to populate your second combo with the one whose name is selected in the first combo?
0
 
mcdown75Commented:
Ok, if that is the case then you would

sub popBox(byval myarray(9) as array)
dim i as integer
for i = 0 to upperbound(myarray)
mycombo.additem(myarray(i))
next
mycombo.index=0
end sub

Pass your array in based on the value that they select and run the loop
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now