Consulting

Results 1 to 8 of 8

Thread: Populating an array with a userform

  1. #1
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location

    Populating an array with a userform

    Is there a standard way to produce to populate a combo box with a list based on an array from a user form?

    For example, the list includes a, b and c and I would like the user to be able to include item d in the array via the user form and also be able to delete selections as well.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I am confused about your problem description. What do you mean by array on userform?

    The combobox and listbox controls have a List property. You can get or put data from/to an array using it.

    If you post an example workbook, it is easier to help.

  3. #3
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    Thanks, I have attached an example of what I would like to achieve.
    Attached Files Attached Files

  4. #4
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    I think that something like this would help with the unique values:

    [VBA]Sub UniqueValues()

    Dim tmp As String
    Dim arr() As String
    Dim cell As Range
    Dim arraycount As Integer

    If Not Selection Is Nothing Then

    tmp = "|"

    For Each cell In Selection
    If (cell <> "") And (InStr(tmp, "|" & cell & "|") = 0) Then
    tmp = tmp & cell & "|"
    End If
    Next cell

    End If

    If Len(tmp) > 0 Then
    tmp = Right(Left(tmp, Len(tmp) - 1), Len(tmp) - 2)
    arr = Split(tmp, "|")
    End If

    For arraycount = 0 To UBound(arr)

    'Sheets("Categories").Range("J8").Cells(arraycount + 1, 1).Value = arr(arraycount)
    Debug.Print arraycount & ". " & arr(arraycount)
    Next arraycount

    End Sub[/VBA]

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi sassora,

    I am probably (actually, hopefully), only going to be up for another 30 minutes or so, but as you just posted... If you spot this right off, could you post in .xls format?

    Mark

  6. #6
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    Sure - I've posted as xls version
    Attached Files Attached Files

  7. #7
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Apologies, as I must be off to bed, but I am not understanding (probably just me being thick-headed) as to:

    "the second containing, sorted component parts"

    a1 
    a1:b1 
    a1:b1:c1 
    a1:b1:c2 
    a1:b1:c3 
    a1:b2 
    a1:b2:c4 
    a1:b2:c5
    and:

    "I would like they (sic) contents of these boxes to be available in array form, so I can work with the contents later"

    I do not understand as to the sort firstly. Are the (Forms toolbar type) listboxes multi-column and a1:b1 represent two columns in one row? Or, is a1:b1 one string that we need to pick apart to sort (at least as I read your input)?

    Thus, it seems unclear to me as to what we are trying to do in storing any value(s) to an array?

    Mark

  8. #8
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    I am defining documents according to work area using data validation. I would like to create a user form that can be used to update the validation lists. The idea is to pass the userform data into an array which can then feed the validation lists.


    The a, b and c represent categories and they are separated by a colon.

    For example

    Subjects:English:Literature
    Subjects:Maths:Algebra
    Subjects:Maths:Logic


    Then I would like to return a list

    Subjects
    Subjects:English
    Subjects:English:Literature
    Subjects:Maths
    Subjects:Maths:Algebra
    Subjects:Maths:Logic

    (basically all of the combinations are shown)
    Attached Files Attached Files
    Last edited by sassora; 07-03-2012 at 04:53 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •