Solved

DataSort absolute values?

Posted on 2016-10-25
5
26 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 33

Accepted Solution

by:
Norie earned 500 total points
Comment Utility
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
Comment Utility
I am getting a syntax error on line 5 thru 10?  When I copy/paste into Mod?
0
 

Author Closing Comment

by:RWayneH
Comment Utility
Appreciate the help.
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
Did you fix the syntax error?
0
 

Author Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now