Consulting

Results 1 to 6 of 6

Thread: Adding item in listbox 1

  1. #1

    Adding item in listbox 1

    Suppose, I have a userform and on this userform, I have a listbox, name it listbox1, containing 4 elements : A, B, C, and D.

    However instead of working directly with A, B, C or D, user might want to work with their simple functions.
    For example he may want to work with A, B, A-D, A-C. Therefore i have to "invent" some way so that user can enter those choices.

    I thought of following:
    On the same userform, just beside of listbox1, there will be a textbox. But user can not write anything by using keyboard, except the mathematical signs. He will only have choice to enter data from the listbox1 entries.

    Fo the current example, in that textbox user can write : A,B,A-D,A-C. Here he will take A, B etc from listbox1 and '-' ',' signs can be entered through keyboard.

    Can anyone help me to write a VBA code for doing this job? Your help will be highly appreciated.

    Thanks and Regards,

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Just give them a multi-select listbox.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Hi Xld, can you please tell me how i can move the items from listbox to next textbox. If possible, can you provide me a skeleton on codes for doing that?

    Regards,

  4. #4
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    273
    Location
    this idea is unresonable for large sets of data, but if you only have 4 options, you could just generat all posiblilies and put them in the list.

  5. #5
    If anyone here please provide me any guidence on how to move the list-items to text box then I can start experimenting.

    Regards,

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim mpText As String
    Dim i As Long
    With Me.ListBox1
    For i = 0 To .ListCount - 1
    If .Selected(i) Then
    mpText = mpText & .List(i) & Chr(10)
    End If
    Next i
    End With
    Me.TextBox1.Text = mpText
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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