Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DataSort absolute values?

Posted on 2016-10-25
5
Medium Priority
?
78 Views
Last Modified: 2016-10-25
How do I remove the absolute value in lines 3 and 6?  The dataset will vary in size.

ActiveWorkbook.Worksheets("MODetails").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("MODetails").Sort.SortFields.Add Key:=Range( _
        "A2:A32"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.Worksheets("MODetails").Sort.SortFields.Add Key:=Range( _
        "C2:C32"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("MODetails").Sort
        .SetRange Range("A1:L32")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveWorkbook.Save
    ActiveWorkbook.Close

Open in new window

0
Comment
Question by:RWayneH
  • 3
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 41859051
Perhaps.
Dim LastRow As Long

    LastRow = Sheets("MODetails").Range("A" & Rows.Count).End(xlUp).Row
    ActiveWorkbook.Worksheets("MODetails").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("MODetails").Sort.SortFields.Add Key:=Range( _
        "A2:A" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.Worksheets("MODetails").Sort.SortFields.Add Key:=Range( _
        "C2:C" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("MODetails").Sort
        .SetRange Range("A1:L" & LastRow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveWorkbook.Save
    ActiveWorkbook.Close

Open in new window


Note I've also changed line 9 as that's actually for the entire range you want to sort by columns A and C.
0
 

Author Comment

by:RWayneH
ID: 41859112
I am getting a syntax error on line 5 thru 10?  When I copy/paste into Mod?
0
 

Author Closing Comment

by:RWayneH
ID: 41859118
Appreciate the help.
0
 
LVL 35

Expert Comment

by:Norie
ID: 41859123
Did you fix the syntax error?
0
 

Author Comment

by:RWayneH
ID: 41859675
Yes, I copied the line numbers too, vba did not like that.  All good.  Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question