Selecting rows

W

Walshy

I am having trouble selecting rows in a macro and deleting
them.

I know you normally would write:
Rows("a1:a3").select
Selection.Delete Shift:=xlUp

problem I am having is the rows are vaiables..

I have wrote code to pick up a set a start & end row as
dim startrow and dim endrow

How do I the select that range ???

I tried Rows(startrow:endrow).select but no joy ???

Help me please...

Thanks
 
T

Tom Ogilvy

Rows(1:3).Delete Shift:=xlup

should have been

Rows("1:3").Delete Shift:=xlup

but the approach with variables is fine.
 
A

Alan Beban

One of the more important aspects of Tom Ogilvy's solution was unstated
(though clear): *avoid* the ".Select" and "Selection". That syntax is
superfluous and inefficient.

Alan Beban
 
D

Dana DeLouis

Just personal preference is to avoid using strings. Here is just one
additional idea.

Dim s, e 'start & end rows to delete
s = 5
e = 10
Rows(s).Resize(e - s + 1).Delete

Note that Excel assumes Shift:=xlUp when it is the entire row.

HTH
Dana DeLouis
 

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