How to populate a userform listbox from excel data

Waterpolo1

New Member
Joined
Sep 8, 2015
Messages
21
Process so far, the problem one is step 3 only:
1. Get file path of document and populate into a listbox (Code below)

Private Sub CommandButton2_Click()
'GetOpenFile MultiSelect will return an Array if more than one is selected
On Error Resume Next

Dim FilePathArray As Variant
FilePathArray = Application.GetOpenFilename(, , , , MultiSelect:=True)
UserForm.EvidenceListBox.AddItem (FilePathArray(1))

' If IsArray(FilePathArray) Then

Dim ArraySize As Long
ArraySize = UBound(FilePathArray, 1) - LBound(FilePathArray, 1)
Dim ArrayPosition As Long
For ArrayPosition = 1 To ArraySize
If Not FilePathArray(ArrayPosition) = Empty Then
UserForm.EvidenceListBox.AddItem (FilePathArray(ArrayPosition))
End If

Next ArrayPosition

2. Submit data to text box in sheet (Code below)
For i = 0 To EvidenceListBox.ListCount - 1
ws.Range("P" & LastRow).Value = ws.Range("P" & LastRow).Value & " | " & EvidenceListBox.List(i)
Next I

3. PROBLEM ONE - I have a button which when I click, retrieve data from the excel sheet into a lisbox. It finds the right list by finding the right ID. current code which doen't work is below:

EvidenceListBox1.Text = ws.Cells(i, 16)
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You can also remove those loops like
Code:
Private Sub CommandButton2_Click()
'GetOpenFile MultiSelect will return an Array if more than one is selected

Dim FilePathArray As Variant
FilePathArray = Application.GetOpenFilename(, , , , MultiSelect:=True)
Me.EvidenceListBox.List = FilePathArray
Ws.Range("P" & lastRow).Value = Join(FilePathArray, "|")
End Sub
 
Upvote 0
Thanks Roderick - That only adds whats in the text box ie one big list. In the loop (Step 2), if there were multiple attachments I separated them out with "|". I need to basically, take this "|" out and just have the file paths in a list again, rather than one big list - any ideas?
 
Upvote 0
How about
Code:
Me.EvidenceListBox.List = Split(Ws.Cells(i, 16), "|")
 
Upvote 0
The code from post#3 is designed to replace the code you supplied in the OP
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top