There is a bit of code I am using to remove rows where if certain text in the column is not present, the row is deleted, thus leaving only the header and the rows that do contain the required text.
The code is as follows and works quite well:
I would like to change the reference from, in this example, column "A", to a previously named range. It would simplify things if the columns were to ever be moved around, so that the code would continue to work.
Here is what I was basically aiming for:
I believe that I have my syntax wrong in the following location:
I just don't see what I have wrong and how to fix it.
Any advice or direction you might provide would be of great help.
-Spydey
The code is as follows and works quite well:
Code:
Sub DeleteRows()Dim r As Long, lr As Long
lr = ActiveWorkbook.Worksheets("Test").Cells(Rows.Count, "[B]A[/B]").End(xlUp).Row
For r = lr To 2 Step -1
If InStr(Cells(r, "A"), "[B]TEXT[/B]") = 0 Then Rows(r).Delete
Next r
End Sub
I would like to change the reference from, in this example, column "A", to a previously named range. It would simplify things if the columns were to ever be moved around, so that the code would continue to work.
Here is what I was basically aiming for:
Code:
Sub DeleteRowsNR()
Dim r As Long, lr As Long
lr = ActiveWorkbook.Worksheets("Test").Cells(Rows.Count, Range("[B]TEXT_RANGE[/B]")).Row
For r = lr To 2 Step -1
If InStr(Cells(r, "A"), "[B]TEXT[/B]") = 0 Then Rows(r).Delete
Next r
End Sub
I believe that I have my syntax wrong in the following location:
Code:
lr = ActiveWorkbook.Worksheets("Trial").Cells(Rows.Count, Range("[B]TEXT_RANGE[/B]")).Row
I just don't see what I have wrong and how to fix it.
Any advice or direction you might provide would be of great help.
-Spydey
Last edited: