Login | |
|
 |
RE: Converting sort macro to VBS usable code ? - 7/19/2006 5:41:42 PM
|
|
 |
|
| |
ginolard
Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
|
Wow. What a coincidence. I was just facing this exact same problem yesterday. Replace the VBA code with this Set objRange = objWorksheetMovies.UsedRange Set objRange2 = objExcel.Range("B2") objRange.Sort objRange2,1,,,1,,1,1,1,False,1
_____________________________
Author of ManagePC - http://managepc.net AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm
|
|
| |
|
|
|
 |
RE: Converting sort macro to VBS usable code ? - 7/19/2006 6:09:38 PM
|
|
 |
|
| |
takeda kozo
Posts: 83
Score: 0
Joined: 11/9/2005
Status: offline
|
Any idea how to change the sort order on columb B ? From ascending to descending .. or vice versa (The code below works, ie: sorts the data, but i just want to change the direction) Do you simply delete a "1" to change the sort order ? Or insert a "0" ? Or what ? +++++++++++++++ oExcel.Cells.Select oExcel.Selection.Sort oExcel.Range("B2"),1,,,1,,1,1,1,False,1 +++++++++++++++
|
|
| |
|
|
|
 |
RE: Converting sort macro to VBS usable code ? - 7/19/2006 9:46:00 PM
|
|
 |
|
| |
ehvbs
Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
|
If I'd use the Excel Docs and the "immediate window" (or the Object Catalog) instead of imagination, I'd come up with: xlAscendig = 1 xlDescending = 2 oExcel.Selection.Sort oExcel.Range("B2"),xlDescending,,,1,,1,1,1,False,1
|
|
| |
|
|
|
 |
RE: Converting sort macro to VBS usable code ? - 7/24/2006 12:47:10 PM
|
|
 |
|
| |
takeda kozo
Posts: 83
Score: 0
Joined: 11/9/2005
Status: offline
|
Yes, I was able to decipher your message :) thank you I am still having a problem with the sorting though. If I try and sort by just the one column, then it works fine....but....i would like to be able to use the 3 different sort orders For example: Sort by Col A - Ascending Then Sort by Col B Descending then sort by Col C Ascending This line is ok: oExcel.Selection.Sort oExcel.Range("B2"),2,,,1,,1,1,1,False,1 '(sorts by col B - Descending) This line is ok: oExcel.Selection.Sort oExcel.Range("R2"),1,,,1,,1,1,1,False,1 '(sorts by col R - Ascending) This line FAILS: oExcel.Selection.Sort oExcel.Range("R2"),1,("B2"),2,("F2"),1,,,1,,1,1,1,False,1 On the line that fails, I would like sort first by: Col R (Ascending) THEN by Col B (Descending) THEN by Col F (Ascending) Thank you for your help so far - TK
|
|
| |
|
|
|
 |
RE: Converting sort macro to VBS usable code ? - 7/25/2006 12:08:31 AM
|
|
 |
|
| |
ehvbs
Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
|
Hi takeda kozo, you know that you need 'oExcel.Range("R2")' to specify the range R2; why do you expect that simple '("B2")' will pass a range to the .Sort method? Why didn't you use the macro recorder to get: Range("A1:C27").Select Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _ , Order2:=xlDescending, Key3:=Range("C1"), Order3:=xlAscending, Header _ :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom and work from that? Perhaps it will help to code in a more lucid (german: übersichtlich) way: Const xlAscending = 1 ... Dim rngR2 : Set rngR2 = oExcel.Range("R2") Dim rngB2 : Set rngB2 = oExcel.Range("B2") Dim rngF2 : Set rngF2 = oExcel.Range("F2") oExcel.Selection.Sort rngR2, xlAscending _ , rngB2, xlDescendig _ , rngF2, xlAscending _ ,,,1,,1,1,1,False,1 (Not tested, I didn't even count the ","). By the way: please include the error message in your posting.
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|