Select row from listbox and pull up relevant data

learningthings

New Member
Joined
Oct 29, 2021
Messages
35
Office Version
  1. 365
Platform
  1. Windows
I am coding a cash register and have the following listbox load a "Register View".
VBA Code:
Sub Reset_Register()
With frmRegister
Dim ws As Worksheet
Dim rng As Range
Dim MyArray
Set ws = Sheets("RegisterView")
Set rng = ws.Range("A1:I" & ws.Range("A" & ws.Rows.Count).End(xlUp).Row)

With .lstRegister
       .Clear
       .ColumnHeads = False
       .ColumnCount = rng.Columns.Count
        '~~> create a one based 2-dim datafield array
        MyArray = rng
         '~~> fill listbox with array values
         .List = MyArray
         '~~> Set the widths of the column here. Ex: For 5 Columns
         '~~> Change as Applicable
         .ColumnWidths = "70;70;70;70;70;70;70;70;70"
         .TopIndex = 0
         .ListIndex = .ListCount - 1
    End With

End With
End Sub

It lists all of the transactions happening during one customer visit, for example a sale and a refund.
Every Sale is recorded on the "Sales" worksheet and every refund is recorded on the "Refund" Worksheet. The .lstRegister acts as a viewing panel.
Every Sale and Refund is linked to a unique ID number which is stored in column A of their respective worksheet. It is also stored in column A in the .lstRegister.
I want to be able to select a row from the listbox and be able to identify the matching row in either the sales or refund worksheet
Next, when clicking cmdEdit, I need frmSales to show up with prefilled information regarding that transaction i.e. fill .txtItemSold from column B of the correct row.

Let me know if there is information you need!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Don't understand fully where your problem lies. If you click on a row of the listbox, then you can get the ID number. and next you can do a range.find to find that ID in the database.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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