Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DataSort absolute values?

Posted on 2016-10-25
5
Medium Priority
?
73 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 34

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 34

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

705 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