Hi guys
This site has helped me a lot with my VBA but I battle to find a proper solution to my issue:
I have a userform that search for a value in column A, it displays the results in the listbox. Example: Search for value "111" and it brings me back the following results back in the listbox "111 David 35". So this means 3 columns matching data is returned.
I want the following to happen if I double click on the item in the listbox it needs to update the value selected in the worksheet eg. strikethrough the row on the sheet to show item has been seleced/done.
Code for my listbox populate:
Formula:
Dim wks As Worksheet
Dim rg As Range
Dim Rng As Range
Dim first_row As Long 'use this to see if the find is looping again
Dim ctr As Integer 'use this to show count of matching records
Dim My_Col As String 'this is used to search part no or item description based on user input
Set wks = Sheets("TeamList")
ListBox1.Clear
My_Col = "A"
'search in the columns based on user input
Set Rng = wks.Columns(My_Col & ":" & My_Col).Find(What:=Me.TextBox1.Value, After:=wks.Range(My_Col & wks.Rows.Count).End(xlUp))
If Not Rng Is Nothing Then
vl = wks.Range(Rng.Address).Value
ctr = 0
ListBox1.Clear
'add the listbox column headers
Me.ListBox1.ColumnCount = 4
Me.ListBox1.AddItem
Me.ListBox1.List(0, 0) = "Team Nr."
Me.ListBox1.List(0, 1) = "Name and Surname"
Me.ListBox1.List(0, 2) = "Meal"
Me.ListBox1.List(0, 3) = "Drink"
first_row = Rng.Row 'row no of the first found
Do Until Rng Is Nothing 'loop through the range
For Each rg In Rng.Rows
If rg.Row > 1 Then
ListBox1.AddItem 'add items to listbox
ListBox1.List(ListBox1.ListCount - 1, 0) = wks.Range("A" & rg.Row).Text
ListBox1.List(ListBox1.ListCount - 1, 1) = wks.Range("B" & rg.Row).Text
ListBox1.List(ListBox1.ListCount - 1, 2) = wks.Range("C" & rg.Row).Text
ListBox1.List(ListBox1.ListCount - 1, 3) = wks.Range("D" & rg.Row).Text
ctr = ctr + 1
End If
Next
Set Rng = wks.Columns(My_Col & ":" & My_Col).FindNext(After:=Rng)
If Rng.Row = first_row Then 'check if find is looping again from the beginning ,if yes then exit do
Exit Do
End If
Loop
End If
Appreciate your help!
Bookmarks