Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

populate Combobox from multiColumn Text file pipe delimiter

vba 2010
userform with
combobox1
Textbox1


Right now loading combobox from text file...but the texfile has 2 columns seperated by a pipe delimiter.

I need to load combobox with this textfile so it shows 2 columns.
Then after i make a selection...in  Textbox1 it will show only the value from Column2 in the combobox



Dim InFilet As Integer
Dim NextTip As String
InFilet = FreeFile
Open "C:\Program Files\Crs Enterprise\iData\Defaults\DescSearch_Slang.txt" For Input As InFilet
While Not EOF(InFilet)
  Line Input #InFilet, NextTip
   UserForm2.ComboBox27.AddItem NextTip
Wend
Close InFilet

Open in new window



Thanks
fordraiders
Avatar of Si Ball
Si Ball
Flag of United Kingdom of Great Britain and Northern Ireland image

load the data into an array and populate the combo with the array.

http://www.mrexcel.com/forum/excel-questions/454709-populating-multi-column-combobox.html
they offer a soltuion of concatenating the data into a 3rd column as only one col is visible in excel... and then storing the 1st item when selected:

Private Sub UserForm_Initialize()
    Dim i As Long
    With ComboBox1
        .ColumnCount = 3
        .ColumnWidths = ";;0"
        .TextColumn = 3
        
        For i = 1 To 10
            .AddItem Range("A1:A10").Cells(i, 1).Value
            .List(.ListCount - 1, 1) = Range("D1:D10").Cells(i, 1).Value
            .List(.ListCount - 1, 2) = .List(.ListCount - 1, 0) & vbTab & .List(.ListCount - 1, 1)
        Next i
        
    End With
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Si Ball
Si Ball
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Any success with the above?  you can use " " instead of VBTAB to space out the visible column...
Avatar of Fordraiders

ASKER

yes, Thanks very much !