Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default SORT: Is it possible to supply operands via function / vba sub?

Hi all,

I am writing a Sub to process a CSV. This code will perform (amongst other
bits) a SORT on the data. However, the sort procedure will vary with the data
- such that the sort Range, Order & Key will vary.
I was hoping it would be possible to supply the range,order & key TO the
Sub, and then use the passed information within the SORT vba code to perform
the function... but I can't find any information regarding declaring the
Order operands etc... can this be done?

I know that the Key can be specified by referencing a cell, but can I just
use an expression directly? What is Order object / operand to be declared as
etc?

Any guidance greatly appreciated. KR

Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default SORT: Is it possible to supply operands via function / vba sub?

sub mysort(target as range,mykey1 as integer, mykey2 as integer, _
mykey3 as integer)

Worksheets("sheet1"). _
Range(target), Cells(MaxRows, 10)).Sort _
Key1:=Worksheets("sheet1").Columns(mykey1), _
Key2:=Worksheets("sheet1").Columns(mykey2), _
Key3:=Worksheets("sheet1").Columns(mykey3), _
Header:=xlNo, DataOption1:=xlSortNormal

sort order uses ther following constant
Const xlAscending = 1
Const xlDescending = 2


"Mike Iacovou" wrote:

Hi all,

I am writing a Sub to process a CSV. This code will perform (amongst other
bits) a SORT on the data. However, the sort procedure will vary with the data
- such that the sort Range, Order & Key will vary.
I was hoping it would be possible to supply the range,order & key TO the
Sub, and then use the passed information within the SORT vba code to perform
the function... but I can't find any information regarding declaring the
Order operands etc... can this be done?

I know that the Key can be specified by referencing a cell, but can I just
use an expression directly? What is Order object / operand to be declared as
etc?

Any guidance greatly appreciated. KR

Mike

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default SORT: Is it possible to supply operands via function / vba sub

thanks joel

i'll give that a try. cheers.

Mike
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default SORT: Is it possible to supply operands via function / vba sub

I got the range wrong. Below is the correction.

Worksheets("sheet1"). _
Range(target).Sort _
Key1:=Worksheets("sheet1").Columns(mykey1), _
Key2:=Worksheets("sheet1").Columns(mykey2), _
Key3:=Worksheets("sheet1").Columns(mykey3), _
Header:=xlNo, DataOption1:=xlSortNormal


"Mike Iacovou" wrote:

thanks joel

i'll give that a try. cheers.

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
Add-ins query wizard operands (criteria tab) Craig Monette Excel Discussion (Misc queries) 0 March 17th 09 04:39 PM
sort function for dates does not sort properly in Office 2007 Exc. Rosalie Excel Worksheet Functions 1 November 22nd 07 10:25 PM
Weeks of Supply Function jeffbert Excel Worksheet Functions 1 January 31st 07 08:57 PM
custom toolbar for operands jdrose Excel Discussion (Misc queries) 2 July 25th 06 04:28 PM
Excel Sort function should not sort the cell formatting! Lisa D.N.1 Excel Worksheet Functions 1 December 28th 04 08:37 PM


All times are GMT +1. The time now is 02:01 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"