Solved

DataSort absolute values?

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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 will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

821 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