Hi,
I'm looking for VBA code that will allow me to delete cells in a worksheet based on text that has been picked in a dropdown list in a combobox in a userform when I click a button. Can you one help???
I have found this code but it doesn't seem to work?:
Private Sub cmdDelete_Click()
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("Data")
lastRow = ws.Range("D" & Rows.Count).End(xlUp).Row
strSearch = ComboBox1.Value
Set aCell = ws.Range("D" & 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