ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is there away? (https://www.excelbanter.com/excel-programming/428274-there-away.html)

Michael Koerner

Is there away?
 
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?

--

Regards
Michael Koerner



Per Jessen

Is there away?
 
Hi

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

Hopes this helps.

Per


"Michael Koerner" 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?

--

Regards
Michael Koerner


Mike H

Is there away?
 
Hi,

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

Mike

"Michael Koerner" wrote:

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?

--

Regards
Michael Koerner



Dana DeLouis

Is there away?
 
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



Michael Koerner wrote:
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?


Michael Koerner

Is there away?
 
Thanks, will try it out.

--

Regards
Michael Koerner


"Per Jessen" wrote in message ...
Hi

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

Hopes this helps.

Per


"Michael Koerner" 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?

--

Regards
Michael Koerner


Michael Koerner

Is there away?
 
Thanks, will try it out.

--

Regards
Michael Koerner


"Mike H" wrote in message ...
Hi,

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

Mike

"Michael Koerner" wrote:

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?

--

Regards
Michael Koerner




All times are GMT +1. The time now is 04:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com