Solved

populate Combobox from multiColumn Text file pipe delimiter

Posted on 2013-11-25
5
419 Views
Last Modified: 2013-11-27
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
0
Comment
Question by:fordraiders
  • 4
5 Comments
 
LVL 15

Expert Comment

by:Simon Ball
ID: 39677646
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
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 39677654
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

0
 
LVL 15

Accepted Solution

by:
Simon Ball earned 500 total points
ID: 39677736
So i put this in the sheet. activte to test it, and it works... showing the 2 values with a tab between them, but on selection, selects "column" 1

Private Sub Worksheet_Activate()
Dim InFilet As Integer
Dim NextTip As String
Dim col1 As String
Dim col2 As String
Dim PipeLoc As Integer

    With UserForm1.ComboBox27
        .ColumnCount = 3
        .ColumnWidths = ";;0"
        .TextColumn = 1


            InFilet = FreeFile
            Open "H:\pipeTest.txt" For Input As InFilet
            While Not EOF(InFilet)
              Line Input #InFilet, NextTip
               'UserForm2.ComboBox27.AddItem NextTip
               PipeLoc = InStr(NextTip, "|")
               col1 = Left(NextTip, PipeLoc - 1)
               col2 = Mid(NextTip, PipeLoc + 1, Len(NextTip) - PipeLoc)
               .AddItem col1
               .List(.ListCount - 1, 1) = col2
               .List(.ListCount - 1, 2) = .List(.ListCount - 1, 0) & vbTab & .List(.ListCount - 1, 1)
            Wend
End With
Close InFilet
UserForm1.Show
End Sub

Open in new window

0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 39680429
Any success with the above?  you can use " " instead of VBTAB to space out the visible column...
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39681230
yes, Thanks very much !
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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