PDA

Click to See Complete Forum and Search --> : VBScript parameters for excel *RESOLVED*


R00tj00se1
Nov 3rd, 2003, 03:12 AM
I tried this in the vbscript forum but didn't get much response. Have deleted it from there and thought I'd try here:


I'm trying to sort a range of columns but I'm having trouble getting the right syntax in VBScript. The VBA code looks like this:

Range("O1:AI5").Select
Selection.Sort Key1:=Range("O1"), Order1:=xlAscending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlLeftToRight

I know that in VBScript I have to use the constants rather than the names (e.g. 1 instead of xlAscending) and that I need to include blanks for parameters that I am not using.
My VBscript code looks something like this:

With oxl
.Columns(sFirstCol & ":" & sLastCol).Select
.Selection.Sort oxl.Range(sFirstCol), 1, , , , , , 0, 1, False, 2
End With

sFirstCol and sLastCol are variables containing the first and last column letter respectively.
I get an unknown runtime error on the selection.sort line when I run the script. Can anyone see where I'm going wrong?
Thanks

Edited to add: does anyone know of a good site that talks about converting VBA parameters to vbscript?

R00tj00se1
Nov 4th, 2003, 02:31 AM
Well, I fiddled around with it and changed it to this to get it working:

With oxl
.Range(sFirstCol & "1").Select
.ActiveCell.Range("A1:" & sLastCol & (nLineCount + 2)).Select
.Selection.Sort oxl.ActiveCell, 1, , , , , , 0, 1, False, 2
End With