Sign in to follow this  
Followers 0
HighlanderSword

Excel Sort

2 posts in this topic

#1 ·  Posted (edited)

Hello,

I need to do a sort with an excel file, listed below is the code I'mm using , I took this from a recorded macro in Excel. I made modfications to it

to reference the $Oexcel_to Variable that I'm using.

When I try and run this it fails on the line

$oExcel_to.ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key=Range("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

At the Add Key part of the string stating that their is a syntax error.

Any Ideas what I'm missing ?

#include <String.au3>

#include <Excel.au3>

#include <Array.au3>

#include <date.au3>

$oExcel_to=_ExcelBookOpen("c:\test1.xlsx",1)

$oExcel_to.Cells.Select

$oExcel_to.ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear

$oExcel_to.ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key=Range("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

With $oExcel_to.ActiveWorkbook.Worksheets("Sheet1").Sort

.SetRange Range("A:A")

.Header = xlYes

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

End With

Edited by HighlanderSword

Share this post


Link to post
Share on other sites



Hello All,

I was able to figure it out, I ended up using the line bwlow toaddress my sort requirement

$oExcel_to.range("A1").sort ($oExcel_to.range ("A:A"))

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0