Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 164
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 164
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 164
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"