Results 1 to 2 of 2

Thread: VBScript parameters for excel *RESOLVED*

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4

    VBScript parameters for excel *RESOLVED*

    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?
    Last edited by R00tj00se1; Nov 4th, 2003 at 03:31 AM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width