Ok, So I have a userform in excel, and I have a textbox called “IMEITextBox” on the form. I have a inventory sheet that have IMEI numbers in Coloum B that I have in stock. When I enter an IMEI number in the IMEITextBox, I want it to delete the row containing that IMEI numbe from sheet “Inventory” when I save. I have researched this over and over for days now. Cant seem to find anything that works for me. Can you assist?
Sub DeleteRows(IMEI)
Dim ws As Worksheet
Dim lastRow As Long, i As Long
Dim strSearch As String
Dim aCell As Range
On Error GoTo Err
Set ws = Sheets("Inventory")
lastRow = ws.Range("IMEIRange" & Rows.Count).End(xlUp).Row
strSearch = IMEITextBox.Value
Set aCell = ws.Range("IMEIRange" & lastRow).Find(What:=strSearch, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
ws.Rows(lastRow).Delete
End If
Exit Sub
Err:
MsgBox Err.Description
End Sub
I have commented the code so that you will not have a problem understanding it… After seeing the code, you will realize that you were very close 😉