Read lines from Excel file and list them in form's ListBox

pitaszek

Board Regular
Joined
Jul 20, 2012
Messages
85
Hi Guys,

My idea is to read the values from the Excel file and list them in ListBox. The idea is a user reads all currently Open tickets that are stored in a workbook and has them displayed in the list box. Then selects an item he'd like to close and just clicks 'Close' button - the status in the Excel file is changed to Closed.

I need a solution, a loop to go through open items and list them. I don't know how to get the Excel item listed appear in the listbox - this is my main problem.

The result should be as below:

____________________________________________
|Task Name ........................................... | Status |
|Pricing ................................................... | Open . |
|Access Management................................. | Open.. |
|Prepare a report for Dave.......................... | Open.. |
|___________________________________________|

_______
| Close |
|______|


Input data:
Task name
Date
Owner
Status
Pricing
dd/mm/yy
Agent A
Open
Reconciliation
dd/mm/yy
Agent A
Closed
Accesses management
dd/mm/yy
Agent B
Open
Send email to Rick
dd/mm/yy
Agent B
Closed
Prepare a report for Dave
dd/mm/yy
Agent B
Open

<tbody>
</tbody>

Regards,
Witek
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
So all these values are in a worksheet correct?
And can we assume "Task name is in column "A" starting in row (2)
And "Status" is in column "D"

Is this correct?

And we will be working with one Activex Listbox and one Activex Command button
 
Upvote 0
So all these values are in a worksheet correct?
And can we assume "Task name is in column "A" starting in row (2)
And "Status" is in column "D"

Is this correct?

And we will be working with one Activex Listbox and one Activex Command button

Yes. That's right. That would be enough to get how to achieve that. I can further expand and adjust the actual columns captured to my needs.
Yes, Activex.

Witek
 
Upvote 0
Try this:
Assuming you have a listbox named "ListBox1"

You will also need a command button to load the values into the list box
This script will load values in column "A" and column "D" into the listbox

And you will need another command button to run your script.

Click on the listbox row you want to change and then click your command button with the second script

Now this script will only work with you selecting just one row in the listbox

Your not allowed to choose more then one row in the listbox. You did not say you wanted to select more then one.


Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
'Loads values into listbox
ListBox1.ColumnCount = 2
ListBox1.Clear
Dim i As Long
Dim b As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
b = 0
    For i = 2 To Lastrow
            
        With ListBox1
            .AddItem
            .List(b, 0) = Cells(i, 1).Value
            .List(b, 1) = Cells(i, 4).Value
                b = b + 1
        End With
    Next
Application.ScreenUpdating = True
End Sub

Code:
Private Sub CommandButton2_Click()
'Mark column "D" as "Closed"
Application.ScreenUpdating = False
If ListBox1.ListIndex < 0 Then MsgBox "You must select some row in the List Box": Exit Sub
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        If Cells(i, 1).Value = ListBox1.List(ListBox1.ListIndex, 0) And Cells(i, 4).Value = "Open" Then Cells(i, 4).Value = "Closed"
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you very much for your reply and engagement. I will play around with the codes but I think this should be fine for me.
 
Upvote 0
Glad I was able to help you. Come back here to Mr. Excel next time you need additional assistance.
Thank you very much for your reply and engagement. I will play around with the codes but I think this should be fine for me.
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,603
Members
449,174
Latest member
ExcelfromGermany

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