LegenDSlayeR
New Member
- Joined
- Nov 26, 2020
- Messages
- 6
- Office Version
- 2016
- Platform
- Windows
Good Evening,
I have create a Userform for Warehouse Air Stock. i have multiple products stored in Air Locations. as you will see in a screenshot. i have 2 listboxes. one that show the airstock worksheet, and the other listbox is a search.
my question is, Is it possible to search A product code, and delete it the row selected using the delete button. i have the delete button working BUT. when i search for the product code it gives me 8 matching results. when i click the delete button it removes one of the TOP LINES 8 in the worksheet. and not the on highlighted in the search list box.
Can anyone one help.
sorry if it doesnt make sense
Reguards
Jamie.
I have create a Userform for Warehouse Air Stock. i have multiple products stored in Air Locations. as you will see in a screenshot. i have 2 listboxes. one that show the airstock worksheet, and the other listbox is a search.
my question is, Is it possible to search A product code, and delete it the row selected using the delete button. i have the delete button working BUT. when i search for the product code it gives me 8 matching results. when i click the delete button it removes one of the TOP LINES 8 in the worksheet. and not the on highlighted in the search list box.
Can anyone one help.
sorry if it doesnt make sense
VBA Code:
These are the lines of code using for both buttons.
Private Sub CommandButton1_Click()
Dim RowNum As Long
RowNum = 2
Do Until Sheets("airstock").Cells(RowNum, 1).Value = ""
If InStr(1, Sheets("airstock").Cells(RowNum, 1).Value, txtsearch.Value, vbTextCompare) > 0 Then
On Erro GoTo next1
lstsearch.AddItem Sheets("airstock").Cells(RowNum, 1).Value
lstsearch.List(lstsearch.ListCount - 1, 1) = Sheets("airstock").Cells(RowNum, 2).Value
lstsearch.List(lstsearch.ListCount - 1, 2) = Sheets("airstock").Cells(RowNum, 3).Value
lstsearch.List(lstsearch.ListCount - 1, 3) = Sheets("airstock").Cells(RowNum, 4).Value
lstsearch.List(lstsearch.ListCount - 1, 4) = Sheets("airstock").Cells(RowNum, 5).Text
lstsearch.List(lstsearch.ListCount - 1, 5) = Sheets("airstock").Cells(RowNum, 6).Value
lstsearch.List(lstsearch.ListCount - 1, 6) = Sheets("airstock").Cells(RowNum, 7).Value
lstsearch.List(lstsearch.ListCount - 1, 7) = Sheets("airstock").Cells(RowNum, 8).Value
End If
next1:
RowNum = RowNum + 1
Loop
lstsearch.RowSource = ""
End Sub
Private Sub CommandButton2_Click()
Dim i As Integer
For i = 0 To Range("A10209").End(xlUp).Row - 1
If lstsearch.Selected(i) Then
Rows(i).Select
Selection.Delete
End If
Next i
End Sub
Reguards
Jamie.