I have a userform that i need a listbox filled with 2 columns from another sheet based on the contents of a Textbox in the userform
I have the Textbox populated, and can fill the listbox column 1
I then need to populate 2 other textboxes based on the selection made in the listbox
TextBox1 holds a claim number (Claim Number is in column C in the source sheet called "WRS Worked Hrs")
Each claim number links to a range of dates (The same date bay be linked to multiple claim numbers)
ListBox1 is then populated with the dates linked to the claim number in TextBox1
Based on the date selected in the ListBox1, i need TextBox3 and TextBox4 populated with the corresponding data from the source sheet from columns E and F (This is to allow the user to change these 2 values and then be able to save the updated values to the source sheet)
Column G in the source sheet holds a unique identifier (since the dates may link to several claim numbers, and claim numbers may link to several dates)
Unique identifier is a Concat ("Claim Number" , _ , "Date") (With the date in Excel serial format)
I have gotten as far as populating the list box with the dates, but as these are not unique values, TextBox3 and TextBox4 are populating with values from the first found instance of that date
I do have a TextBox5 that can hold the unique identifier if needed to populate the other textboxes
This is the code i have so far:
Below is a sample of the data i the source sheet (WRS Worked Hrs)
Column C has the claim number
Column D has the date list
Column E has the data for TextBox3 and column F has the data for TextBox4
Column G has the unique identifier for each entry
[/CODE]
I have the Textbox populated, and can fill the listbox column 1
I then need to populate 2 other textboxes based on the selection made in the listbox
TextBox1 holds a claim number (Claim Number is in column C in the source sheet called "WRS Worked Hrs")
Each claim number links to a range of dates (The same date bay be linked to multiple claim numbers)
ListBox1 is then populated with the dates linked to the claim number in TextBox1
Based on the date selected in the ListBox1, i need TextBox3 and TextBox4 populated with the corresponding data from the source sheet from columns E and F (This is to allow the user to change these 2 values and then be able to save the updated values to the source sheet)
Column G in the source sheet holds a unique identifier (since the dates may link to several claim numbers, and claim numbers may link to several dates)
Unique identifier is a Concat ("Claim Number" , _ , "Date") (With the date in Excel serial format)
I have gotten as far as populating the list box with the dates, but as these are not unique values, TextBox3 and TextBox4 are populating with values from the first found instance of that date
I do have a TextBox5 that can hold the unique identifier if needed to populate the other textboxes
This is the code i have so far:
VBA Code:
Private Sub UserForm_Activate()
Dim rngEmpM As Range
Dim rngListM As Range
Dim strSelectedM As String
Dim LastRowM As Long
TextBox1.Value = ThisWorkbook.Worksheets("WRS P1").Range("O1").Value
TextBox2.Value = ThisWorkbook.Worksheets("WRS P1").Range("U5").Value
ListBox1.ColumnCount = 2
strSelectedM = ThisWorkbook.Worksheets("WRS P1").Range("O1").Value
LastRowM = Worksheets("WRS Worked Hrs").Range("C" & Rows.Count).End(xlUp).Row
Set rngListM = Worksheets("WRS Worked Hrs").Range("C2:C" & LastRowM)
For Each rngEmpM In rngListM
If rngEmpM.Value = strSelectedM Then
Me.ListBox1.AddItem rngEmpM.Offset(, 8)
End If
Next rngEmpM
End Sub
Private Sub ListBox1_Click()
Dim ws As Worksheet
Dim iRow As Long
Set ws = ThisWorkbook.Worksheets("WRS Worked Hrs")
With Me
iRow = Me.ListBox1.ListIndex + 4
.TextBox3.Value = ws.Cells(iRow, 2)
.TextBox4.Value = ws.Cells(iRow, 6)
End With
End Sub
Below is a sample of the data i the source sheet (WRS Worked Hrs)
Column C has the claim number
Column D has the date list
Column E has the data for TextBox3 and column F has the data for TextBox4
Column G has the unique identifier for each entry
[/CODE]
Excel Formula:
[TABLE]
[TR]
[TD]Emp ID[/TD]
[TD]Employee[/TD]
[TD]Claim[/TD]
[TD]Week Start[/TD]
[TD]Hrs Work[/TD]
[TD]Paid $[/TD]
[TD]Week ID[/TD]
[/TR]
[TR]
[TD][RIGHT]1234[/RIGHT][/TD]
[TD]Bug, June MS[/TD]
[TD]3894797[/TD]
[TD][RIGHT]14/06/2021[/RIGHT][/TD]
[TD][RIGHT]8[/RIGHT][/TD]
[TD][RIGHT]442.68[/RIGHT][/TD]
[TD]3894797_44361[/TD]
[/TR]
[TR]
[TD][RIGHT]1234[/RIGHT][/TD]
[TD]Bug, June MS[/TD]
[TD]3894797[/TD]
[TD][RIGHT]21/06/2021[/RIGHT][/TD]
[TD][RIGHT]16[/RIGHT][/TD]
[TD][RIGHT]505.92[/RIGHT][/TD]
[TD]3894797_44368[/TD]
[/TR]
[TR]
[TD][RIGHT]1234[/RIGHT][/TD]
[TD]Bug, June MS[/TD]
[TD]3894797[/TD]
[TD][RIGHT]28/06/2021[/RIGHT][/TD]
[TD][RIGHT]16[/RIGHT][/TD]
[TD][RIGHT]505.92[/RIGHT][/TD]
[TD]3894797_44375[/TD]
[/TR]
[TR]
[TD][RIGHT]1234[/RIGHT][/TD]
[TD]Bug, June MS[/TD]
[TD]3894797[/TD]
[TD][RIGHT]5/07/2021[/RIGHT][/TD]
[TD][RIGHT]16[/RIGHT][/TD]
[TD][RIGHT]584.97[/RIGHT][/TD]
[TD]3894797_44382[/TD]
[/TR]
[TR]
[TD][RIGHT]2345[/RIGHT][/TD]
[TD]Bloggs, Joey MS[/TD]
[TD]3857810[/TD]
[TD][RIGHT]14/06/2021[/RIGHT][/TD]
[TD][RIGHT]12[/RIGHT][/TD]
[TD][RIGHT]347.76[/RIGHT][/TD]
[TD]3857810_44361[/TD]
[/TR]
[TR]
[TD][RIGHT]2345[/RIGHT][/TD]
[TD]Bloggs, Joey MS[/TD]
[TD]3857810[/TD]
[TD][RIGHT]21/06/2021[/RIGHT][/TD]
[TD][RIGHT]12[/RIGHT][/TD]
[TD][RIGHT]347.76[/RIGHT][/TD]
[TD]3857810_44368[/TD]
[/TR]
[TR]
[TD][RIGHT]2345[/RIGHT][/TD]
[TD]Bloggs, Joey MS[/TD]
[TD]3857810[/TD]
[TD][RIGHT]28/06/2021[/RIGHT][/TD]
[TD][RIGHT]20[/RIGHT][/TD]
[TD][RIGHT]597.8[/RIGHT][/TD]
[TD]3857810_44375[/TD]
[/TR]
[TR]
[TD][RIGHT]2345[/RIGHT][/TD]
[TD]Bloggs, Joey MS[/TD]
[TD]3857810[/TD]
[TD][RIGHT]5/07/2021[/RIGHT][/TD]
[TD][RIGHT]20[/RIGHT][/TD]
[TD][RIGHT]597.8[/RIGHT][/TD]
[TD]3857810_44382[/TD]
[/TR]
[TR]
[TD][RIGHT]3456[/RIGHT][/TD]
[TD]Happy, Sappy MS[/TD]
[TD]3087863[/TD]
[TD][RIGHT]14/06/2021[/RIGHT][/TD]
[TD][RIGHT]17[/RIGHT][/TD]
[TD][RIGHT]727.26[/RIGHT][/TD]
[TD]3087863_44361[/TD]
[/TR]
[TR]
[TD][RIGHT]3456[/RIGHT][/TD]
[TD]Happy, Sappy MS[/TD]
[TD]3087863[/TD]
[TD][RIGHT]21/06/2021[/RIGHT][/TD]
[TD][RIGHT]0[/RIGHT][/TD]
[TD][RIGHT]0[/RIGHT][/TD]
[TD]3087863_44368[/TD]
[/TR]
[TR]
[TD][RIGHT]3456[/RIGHT][/TD]
[TD]Happy, Sappy MS[/TD]
[TD]3087863[/TD]
[TD][RIGHT]28/06/2021[/RIGHT][/TD]
[TD][RIGHT]0[/RIGHT][/TD]
[TD][RIGHT]0[/RIGHT][/TD]
[TD]3087863_44375[/TD]
[/TR]
[TR]
[TD][RIGHT]3456[/RIGHT][/TD]
[TD]Happy, Sappy MS[/TD]
[TD]3087863[/TD]
[TD][RIGHT]5/07/2021[/RIGHT][/TD]
[TD][RIGHT]0[/RIGHT][/TD]
[TD][RIGHT]0[/RIGHT][/TD]
[TD]3087863_44382[/TD]
[/TR]
[TR]
[TD][RIGHT]4567[/RIGHT][/TD]
[TD]Doe, John MR[/TD]
[TD]3887940[/TD]
[TD][RIGHT]14/06/2021[/RIGHT][/TD]
[TD][RIGHT]26[/RIGHT][/TD]
[TD][RIGHT]1181.01[/RIGHT][/TD]
[TD]3887940_44361[/TD]
[/TR]
[TR]
[TD][RIGHT]4567[/RIGHT][/TD]
[TD]Doe, John MR[/TD]
[TD]3887940[/TD]
[TD][RIGHT]21/06/2021[/RIGHT][/TD]
[TD][RIGHT]37[/RIGHT][/TD]
[TD][RIGHT]1490.88[/RIGHT][/TD]
[TD]3887940_44368[/TD]
[/TR]
[TR]
[TD][RIGHT]4567[/RIGHT][/TD]
[TD]Doe, John MR[/TD]
[TD]3887940[/TD]
[TD][RIGHT]28/06/2021[/RIGHT][/TD]
[TD][RIGHT]38.5[/RIGHT][/TD]
[TD][RIGHT]1393.65[/RIGHT][/TD]
[TD]3887940_44375[/TD]
[/TR]
[TR]
[TD][RIGHT]4567[/RIGHT][/TD]
[TD]Doe, John MR[/TD]
[TD]3887940[/TD]
[TD][RIGHT]5/07/2021[/RIGHT][/TD]
[TD][RIGHT]40[/RIGHT][/TD]
[TD][RIGHT]1328.04[/RIGHT][/TD]
[TD]3887940_44382[/TD]
[/TR]
[/TABLE]