AddItem in ListBox

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi...

I created a ListBox in my UserForm. I am pulling in data from a couple of sources that I want to display in a cloumn form in the ListBox. What I mean is, The first item on a line in the ListBox is the 4 digit location ID, the second item on the same line is the Location Name, the third item is a task description (wrapped).

Each of the items need to be lined up vertically for each line that I put into the listbox. Example:

Loc Location Name Tasks
1234 Somewhere VA Task 1 - Build system
1234 Somewhere VA Task 2 - Ship System
2345 Somewhere WA Task 1 - Schedule project
.
.


I tried building an array of the items then did an AddItem. I received an runtime error.

It there a way to build and add the above and, allow the user to double click on any line which will then allow me to perform other functions?

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Code:
    v = Array("Loc", "Location Name", "Tasks", _
              "1234", "Somewhere VA", "Task 1 - Build system", _
              "1234", "Somewhere VA", "Task 2 - Ship System", _
              "2345", "Somewhere WA", "Task 1 - Schedule project")
              
    With ListBox1
        .ColumnCount = 3
        .ColumnWidths = "40;75;100"
        For r = 0 To 3
            .AddItem v(r * 3)
            .List(.ListCount - 1, 1) = v(r * 3 + 1)
            .List(.ListCount - 1, 2) = v(r * 3 + 2)
        Next r
    End With
 
Upvote 0
Thanks AlphaFrog... Works just as I hoped...

One more question. In the ListBox1, if I click on an item, I immediately kick off the listbox1_click sub. This is very good except I was hoping to require a double click on the item. I tried Private Sub ListBox1_DoubleClick() but nothing happens when I double click an item.

Any suggestions?

Thanks again.
 
Upvote 0
Actually two questions... The one in the previous post plus--

Is it possible to have the 3rd column wrap the text?

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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