I'm trying to delete a lot of rows in my Excel sheet.
My VBA is really simple:
Sub delNA()
lr = Cells(Rows.Count, "A").End(xlUp).Row 'find last row
For i = lr To 2 Step -1 'loop thru backwards, finish at 2 for headers
If Cells(i, "H").Text = "#N/A" Then Rows(i).EntireRow.Delete
Next i
End Sub
But my problem is that sometimes my headers are different. In this case the header BTEX (Sum) Is in H2, but sometimes that parameter is in G2 and sometimes it's in E2, so what I'm trying to do is make the VBA search for the header name, so instead of H the criteria is "BTEX (Sum)".
Is there a way to make the VBA run in the column where the value in row 2 is "BTEX (Sum)"