×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Excel Sort's Add vs Add2

Excel Sort's Add vs Add2

Excel Sort's Add vs Add2

(OP)
When I want to Sort the data in Excel, and I record a macro to give me the syntax in VBA, I get:

CODE

ActiveWorkbook.Worksheets("DATA").Sort.SortFields.Add2 Key:=Range("D2:D65"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal 

But other versions of Excel (32-bit vs 64-bit) will not take Add2, I need to change it to just Add:

CODE

ActiveWorkbook.Worksheets("DATA").Sort.SortFields.Add Key:=Range("D2:D65"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal 

because if I leave Add2, my app will crash with "Object doesn't support this property or method" error on other computers. sad

What's the difference between Add and Add2? And why does Excel give me Add2?


---- Andy

There is a great need for a sarcasm font.

RE: Excel Sort's Add vs Add2

Add2 allows for a subfield

https://docs.microsoft.com/en-us/office/vba/api/ex.... But since its an optional field, why couldn't you use Add2 without that argument?

BTW, I never knew that.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Excel Sort's Add vs Add2

(OP)
So, it looks like Excel assumes I will need a SubField in my Sort even if I do not provide one.
And another Excel says: "What are you talking about here?" ponder And crashes. hairpull


---- Andy

There is a great need for a sarcasm font.

RE: Excel Sort's Add vs Add2

This Add2 statement works on my 32-bit install.

CODE -->

ActiveWorkbook.Worksheets("T9 TS CO3").ListObjects("TS").Sort.SortFields.Add2 _
        Key:=Range("TS[T10 Section]"), SortOn:=xlSortOnValues, Order:=xlAscending _
        , DataOption:=xlSortNormal 

RE: Excel Sort's Add vs Add2

Misquote, C Sir, "Add2 Sorté?" 🗡

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close