Is there away?

  • Thread starter Thread starter Michael Koerner
  • Start date Start date
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?
 
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?
 
Hi,

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

Mike
 
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
 
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?
 
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
 
Back
Top