Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Sort's Add vs Add2

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,509
US
When I want to [tt]Sort[/tt] the data in Excel, and I record a macro to give me the syntax in VBA, I get:

Code:
ActiveWorkbook.Worksheets("DATA").Sort.SortFields.Add[highlight #8AE234]2[/highlight] Key:=Range("D2:D65"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

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

Code:
ActiveWorkbook.Worksheets("DATA").Sort.SortFields.[highlight #FCAF3E]Add[/highlight] Key:=Range("D2:D65"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

because if I leave [tt]Add2[/tt], my app will crash with "Object doesn't support this property or method" error on other computers. :-(

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



---- Andy

There is a great need for a sarcasm font.
 
Add2 allows for a subfield

But since its an optional field, why couldn't you use Add2 without that argument?

BTW, I never knew that.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
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.
 
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
 
Misquote, C Sir, "Add2 Sorté?" 🗡

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top