0

I have this code that works perfectly:

    ActiveWorkbook.Worksheets("compleanni").Sort.SortFields.Add2 Key:=Range( _
                                                                       "I6:I23"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers

I'd like to change it like this:

myorder="xlAscending"
....
....
Order:=myorder

but it doesn't work: I get run-time error 13. Any suggestions?

2
  • Get rid of the quotation marks in the assignment and it should work. Commented Dec 16, 2020 at 17:14
  • try myorder = xlAscending Commented Dec 16, 2020 at 17:14

1 Answer 1

1

xlAscending is a predefined constant in VBA (Excel), its type is long (value is 1, but that's not important).

Dim your variable myorder as Long and assing the constant:

Dim myorder as Long
myorder = xlAscending ' (or xlDescending)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.