+ Reply to Thread
Results 1 to 3 of 3

Report not sorting properly

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2012
    Location
    Auckland New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    15

    Report not sorting properly

    I am trying to run some reports to get summary information but it only works once and then does not sort properly. I am copying the visible cells from one worksheet which is filtered on date and pasting them to another worksheet. I then want to sort column B and subtotal at each change in catergory (B) and then hide the detail so I only get the totals.

    This works fine the first time I run it but not again after. I tried clearing the contents of the destination sheet prior to running the macro but it still is not working. Seems to lose the sort. Here is my code>

    Sub PurchasesCategory()
    
        Sheets("Purchases").Select
        Application.Run _
            "'adjusted whangateau shop model (version 1).xls'!MyFilterPurchases"
        Range("A4:G5001").Select
        Selection.SpecialCells(xlCellTypeVisible).Select
        Selection.Copy
        Sheets("PurchaseReports").Select
        Range("A4").Select
        ActiveSheet.Paste
           
           Range("B4").Select
        Application.CutCopyMode = False
        Range("A4:G5001").Sort Key1:=Range("B5"), Order1:=xlAscending, Header:= _
            xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
        Range("A4:G5001").Select
        Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(6, 7), _
            Replace:=True, PageBreaks:=False, SummaryBelowData:=True
        ActiveSheet.Outline.ShowLevels RowLevels:=2
    End Sub

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Report not sorting properly

    Hi nzkazza

    If you'd like tested code please post a copy of your file with a description of what you want to do...one of us may be able to help.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    08-16-2012
    Location
    Auckland New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Report not sorting properly

    Thanks John
    I answered my own question just after I had posted. I was clearing the contents but had not removed the subtotals. Now the macro goes to the destination file first, removes all subtotals, clears contents then goes and gets the new data and it works perfectly. Can't believe I had spent soo many hours for something so simple.
    Karen

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1