VBA Strings and Arrays

Posted on 2004-11-16
Last Modified: 2012-06-27
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

Question by:borris111698
    LVL 2

    Expert Comment

    Try this

    dim i as integer
    For i = 0 to upperbound(A)
    myCombo.index = 0

    This should loop through your array and add each item to your combo box.

    Author Comment

    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..
    LVL 76

    Expert Comment

    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?
    LVL 2

    Accepted Solution

    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)
    end sub

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
    I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
    This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
    Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now