Selecting offset cells

Z

Zygan

Just a quick enquiry if some one will
thanks.

i have a macro that checks the cell value and if the cell value = my
value then i want it to delete the whole row
However i just need a code that can either derive the row number from
and active cell or select and delete a row depending on the active
cell
thanks
 
B

Bob Phillips

You do't need to check the active cell or select anything, all you need to
do is loop through a range checking it. Also, when deleting, it is always
best to work bottom-up.

For example, this dchecks column A and deletes the row

Sub Test()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(,"A").Value = "myValue" Then
Rows(i).delete
End If
Next i

End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Top