This is the code for the popup box.
Option Explicit
Sub delete_rows()
Dim lrow As Long, i As Long
Dim delname As String
With Worksheets("Sheet1")
delname = InputBox("Please provide the name to be retained.", "Name:")
lrow = .Range("F" & .Rows.Count).End(xlUp).Row
For i = lrow To 6 Step -1
If UCase(.Range("F" & i).Value) <> UCase(delname) Then
.Rows(i).Delete
lrow = lrow - 1
End If
Next i
End With
End Sub
This is the code if the name is provided in a cell -
Option Explicit
Sub delete_rows()
Dim lrow As Long, i As Long
Dim delname As String
With Worksheets("Sheet1")
delname = .Range("AA1").Value
lrow = .Range("F" & .Rows.Count).End(xlUp).Row
For i = lrow To 6 Step -1
If UCase(.Range("F" & i).Value) <> UCase(delname) Then
.Rows(i).Delete
lrow = lrow - 1
End If
Next i
End With
End Sub
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
Choose Insert | Module
Where the cursor is flashing, choose Edit | Paste
To run the Excel VBA code:
Choose View | Macros
Select a macro in the list, and click the Run button.
Bookmarks