bloomingflower
New Member
- Joined
- Mar 9, 2020
- Messages
- 19
- Office Version
- 2019
- Platform
- Windows
Hi,
Please help me make a code that will be asking for name and then if this name is not present from A - H column, macro should remove this row. I have such code, but it is not working. I think that there is a problem with selecting range, but amount of rows differs, so I decided to choose the whole column.
Please help me make a code that will be asking for name and then if this name is not present from A - H column, macro should remove this row. I have such code, but it is not working. I think that there is a problem with selecting range, but amount of rows differs, so I decided to choose the whole column.
VBA Code:
Sub Removerows()
Application.ScreenUpdating = False
Name = InputBox("Enter name")
Dim xRow As Range
Dim rng As Range
Dim WorkRng As Range
On Error Resume Next
Set WorkRng = Range("A:H").Select
Application.ScreenUpdating = False
For i = WorkRng.Rows.Count To 1 Step -1
Set xRow = WorkRng.Rows(i)
Set rng = xRow.Find(Name, LookIn:=xlValues)
If rng Is Nothing Then
xRow.Delete
End If
Next
Application.ScreenUpdating = True
End Sub