I am using the following code to try and delete entire rows when it has less than 4 characters in the specific “NAME” column. (ie a column with the header in row 1 being NAME) The database currently has around 10,000 rows. I know the code right now is close, but I am getting a VB error when trying to run it. I think I might be searching for the specific column by name wrong.
Sub Macro2()
' Macro to delete rows if there are less than 4 in the NAME column
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("NAME" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
If Len(Range("NAME" & i).Value) < 4 Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub
Edit: I am getting the VBA error in the following line:
LR = Range("NAME" & Rows.Count).End(xlUp).Row
As others have alluded to in the above comments, your statement
and also,
just don’t make any sense to VBA in your given programs, as they are the equivalent to saying.
And unless you have a Defined Name in your workbook called Name81 (or any other number) that code will produce a Run-Time Error.
I think this gets you want you want: