Counter to delete a row

G

Guest

I have a macro which deletes row 6 from my worksheet.
eg "Rows("6:6").Select"
However I want to amend this code so that instead of deleting row 6 I want
to delete the row number equal to a counter value that I have defined.
When I come to a row I want to delete, what value do I put in the code
"Rows("?:?").Select" to delete the row number to the value of the counter.

thanks for your help
 
N

Norman Jones

Hi Chris,

It is unnecessary to select a row in order to delete it. Normally, when
deleting rows, it is easier to start at the bottom and work up.

Perhaps try something like:

'=============>>
Public Sub Tester001()
Dim i As Long
Const startRow As Long = 2
Const endRow As Long = 100

For i = endRow To startRow Step -1
If Cells(i, "A").Value > 10 Then
Rows(i).Delete
End If
Next i

End Sub
'<<=============
 
G

Guest

Thanks Norman,
However, I'm afraid I haven't been able to get that piece of code to work.
I'm probably doing something wrong so I'll persevere.

regards

Chris
 
N

Norman Jones

Hi Chris,
Thanks Norman,
However, I'm afraid I haven't been able to get that piece of code to work.
I'm probably doing something wrong so I'll persevere.

Why not post your problematic code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top