Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Sort by two columns using VB Script

Hello,

I'm trying to sort an Excel spreadsheet by A1 then B1. I recorded a macro
and looked at the VBA code and it looks like I have the syntax correct, but
I get a "Reference is not valid" error. Below is some code with comments.
Thanks.

Set objExcelRange1 = objExcelWs.UsedRange
Set objExcelRange2 = objExcel.Range("A1")
Set objExcelRange3 = objExcel.Range("B1")
objExcelRange1.Sort objExcelRange2,1,,,,,,,1 '<< This works ok for sorting
by A1 only
objExcelRange1.Sort objExcelRange2,1,objExcelRange3,1,,,,,1 '<< I get an
error here

--
Regards,
Martin X.
MCSA: M


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Sort by two columns using VB Script

there is an additional argument between Key2 and Order2

expression.Sort(Key1, Order1, Key2, Type, Order2, Key3, Order3, Header,
OrderCustom, MatchCase, Orientation, SortMethod, DataOption1, DataOption2,
DataOption3)

it should be

objExcelRange1.Sort objExcelRange2,1,objExcelRange3,,1,,,,1
I would guess

--
Regards,
Tom Ogilvy



--
Regards,
Tom Ogilvy


"Martin X." wrote:

Hello,

I'm trying to sort an Excel spreadsheet by A1 then B1. I recorded a macro
and looked at the VBA code and it looks like I have the syntax correct, but
I get a "Reference is not valid" error. Below is some code with comments.
Thanks.

Set objExcelRange1 = objExcelWs.UsedRange
Set objExcelRange2 = objExcel.Range("A1")
Set objExcelRange3 = objExcel.Range("B1")
objExcelRange1.Sort objExcelRange2,1,,,,,,,1 '<< This works ok for sorting
by A1 only
objExcelRange1.Sort objExcelRange2,1,objExcelRange3,1,,,,,1 '<< I get an
error here

--
Regards,
Martin X.
MCSA: M



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Sort by two columns using VB Script

Yep, that was it. Thanks.

--
Regards,
Martin X.
MCSA: M


"Tom Ogilvy" wrote in message
...
there is an additional argument between Key2 and Order2

expression.Sort(Key1, Order1, Key2, Type, Order2, Key3, Order3, Header,
OrderCustom, MatchCase, Orientation, SortMethod, DataOption1, DataOption2,
DataOption3)

it should be

objExcelRange1.Sort objExcelRange2,1,objExcelRange3,,1,,,,1
I would guess

--
Regards,
Tom Ogilvy



--
Regards,
Tom Ogilvy


"Martin X." wrote:

Hello,

I'm trying to sort an Excel spreadsheet by A1 then B1. I recorded a macro
and looked at the VBA code and it looks like I have the syntax correct,
but
I get a "Reference is not valid" error. Below is some code with comments.
Thanks.

Set objExcelRange1 = objExcelWs.UsedRange
Set objExcelRange2 = objExcel.Range("A1")
Set objExcelRange3 = objExcel.Range("B1")
objExcelRange1.Sort objExcelRange2,1,,,,,,,1 '<< This works ok for sorting
by A1 only
objExcelRange1.Sort objExcelRange2,1,objExcelRange3,1,,,,,1 '<< I get an
error here

--
Regards,
Martin X.
MCSA: M





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
Script to sort tables Jeremy Excel Discussion (Misc queries) 1 October 30th 09 02:23 PM
Sort Column Script Bernie New Users to Excel 3 January 23rd 07 05:52 PM
Sort Column Script Bernie Excel Programming 0 January 22nd 07 03:35 PM
need help righting script to sort rows alphabetically then seperate them to line up [email protected] Excel Programming 2 November 15th 05 04:03 PM
need help righting script to sort rows alphabetically then seperate them to line up [email protected] Excel Worksheet Functions 0 November 15th 05 01:23 AM


All times are GMT +1. The time now is 06:37 PM.

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"