Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Varying Data Sort Macro.

Hi,
I am trying to create a macro that does a data sort for me.
The problem I am having is that the data starts from say cell A6 and the end
varies depending on how many new records have been added... new records are
always added at the end.
I was thinking is it possible to put a value say "valuehere" in the cell
below the last field/record so that even when inserting a row that value will
always be there at the end of the data as the row will be inserted above
that... Sorry im confussing myself here !! reson being is there then a way to
say in the macro find valuehere and return the "Cell value" then select
range A6:"Cell Value" then data sort say by col C.... ie.

1 A 10
2 B 20
Valuehere

or if a row is inserted then

1 A 10
2 B 20
3 C 30
Valuehere

I hope this makes sence and someone can help, there is probably a big time
easier answer please help...

Regards

Mike

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Varying Data Sort Macro.

How about

set rng = Range(range("A6"),range("A6").End(xldown)).resize( ,2)
rng.Sort Key1:=Range("A6")
this would give you what you describe without having the valuehere entry.

change the 2 to reflect the number of columns you have.

if you want the valuehere entry

set rng1 = Cells.Find("valuehere")
if not rng1 is nothing then
set rng = Range(ange("A6"), rng1)
rng.Sort Key1:=Range("A6")

--
Regards,
Tom Ogilvy

"MyKool" wrote in message
...
Hi,
I am trying to create a macro that does a data sort for me.
The problem I am having is that the data starts from say cell A6 and the

end
varies depending on how many new records have been added... new records

are
always added at the end.
I was thinking is it possible to put a value say "valuehere" in the cell
below the last field/record so that even when inserting a row that value

will
always be there at the end of the data as the row will be inserted above
that... Sorry im confussing myself here !! reson being is there then a way

to
say in the macro find valuehere and return the "Cell value" then select
range A6:"Cell Value" then data sort say by col C.... ie.

1 A 10
2 B 20
Valuehere

or if a row is inserted then

1 A 10
2 B 20
3 C 30
Valuehere

I hope this makes sence and someone can help, there is probably a big time
easier answer please help...

Regards

Mike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Varying Data Sort Macro.

Hi,
Try:

Lastrow=Cells(rows.count,"A").end(xlup).row <==== change column if required

and set your sort range to

Range("A6:A" & lastrow)

HTH

"MyKool" wrote:

Hi,
I am trying to create a macro that does a data sort for me.
The problem I am having is that the data starts from say cell A6 and the end
varies depending on how many new records have been added... new records are
always added at the end.
I was thinking is it possible to put a value say "valuehere" in the cell
below the last field/record so that even when inserting a row that value will
always be there at the end of the data as the row will be inserted above
that... Sorry im confussing myself here !! reson being is there then a way to
say in the macro find valuehere and return the "Cell value" then select
range A6:"Cell Value" then data sort say by col C.... ie.

1 A 10
2 B 20
Valuehere

or if a row is inserted then

1 A 10
2 B 20
3 C 30
Valuehere

I hope this makes sence and someone can help, there is probably a big time
easier answer please help...

Regards

Mike

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
varying table length in a MACRO tlwhite Excel Discussion (Misc queries) 2 March 16th 10 04:10 PM
Formatting/Totalling Macro with varying rows of data MSteckbeck Excel Discussion (Misc queries) 2 February 5th 08 10:41 PM
Macro: how to set a print area of varying size? Dave D Excel Discussion (Misc queries) 1 September 19th 06 12:50 PM
Using Varying Range Size in Macro Charles Allen[_2_] Excel Programming 1 May 16th 05 12:48 AM
Varying a macro based on a cell's value Neal Zimm Excel Programming 4 December 27th 04 06:37 AM


All times are GMT +1. The time now is 08:58 AM.

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

About Us

"It's about Microsoft Excel"