Is there away?

M

Michael Koerner

I have a macro with the following line:

Range("A1:G1024").Sort Key1:=Range("E2"),

Is there a way to code it so that whenever I add a new item I don't have to continually edit the macro, and change the end range value to accommodate the newly inserted item?
 
P

Per Jessen

Hi

Set SortRange=Range("A1" ,Range("G" & Rows.Count).end(xlup))
SortRange.Sort Key1:=Range("E2")

Hopes this helps.

Per


"Michael Koerner" <[email protected]> skrev i meddelelsen
I have a macro with the following line:

Range("A1:G1024").Sort Key1:=Range("E2"),

Is there a way to code it so that whenever I add a new item I don't have to
continually edit the macro, and change the end range value to accommodate
the newly inserted item?
 
M

Mike H

Hi,

lastrow = Cells(Rows.Count, "G").End(xlUp).Row
Range("A1:G" & lastrow).Sort Key1:=Range("E2")

Mike
 
D

Dana DeLouis

Depending on your SortFields, you may be able to get away with this if
Column H:H is clear. The idea being that a single cell tells Excel to
use the "Current Region."

Sub Demo()
[E1].Sort [E1]
End Sub

= = =
Dana DeLouis
 
M

Michael Koerner

Thanks, will try it out.

--

Regards
Michael Koerner


Hi

Set SortRange=Range("A1" ,Range("G" & Rows.Count).end(xlup))
SortRange.Sort Key1:=Range("E2")

Hopes this helps.

Per


"Michael Koerner" <[email protected]> skrev i meddelelsen
I have a macro with the following line:

Range("A1:G1024").Sort Key1:=Range("E2"),

Is there a way to code it so that whenever I add a new item I don't have to
continually edit the macro, and change the end range value to accommodate
the newly inserted item?
 
M

Michael Koerner

Thanks, will try it out.

--

Regards
Michael Koerner


Hi,

lastrow = Cells(Rows.Count, "G").End(xlUp).Row
Range("A1:G" & lastrow).Sort Key1:=Range("E2")

Mike
 

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

Similar Threads


Top