+ Reply to Thread
Results 1 to 2 of 2

How to sort rows in sheet1 by using the predefined order of locations specified in sheet4

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-15-2014
    Location
    london
    MS-Off Ver
    2013
    Posts
    111

    How to sort rows in sheet1 by using the predefined order of locations specified in sheet4

    Hi All,

    With below macro code I am able to create the report as shown in Sheet1.
    Now I would like to continue the code with some more modifications,
    All I want to do is - I would like to group the locations & insert few rows in sheet1 based on the order criteria shown in Sheet4 (Order shown in sheet1 is fixed).
    So my final report should be present as shown in Sheet “Summary”.

    Please help me with modifying the code.

    Thank you in advance.

    Private Sub CommandButton1_Click()
    
    Dim PvtTbl As PivotTable
    Dim PvtTblCache As PivotCache
    Dim ws As Worksheet, wsPvtTbl As Worksheet
    Dim rng As Range, Pvtrng As Range, Pvtcell As Range, Mrng As Range
    Dim lr As Long, Pvtlr As Long
    Application.ScreenUpdating = False
    Set ws = Sheets("Sheet3")
    lr = ws.Cells(Rows.Count, 2).End(xlUp).Row
    Set rng = ws.Range("A1:E" & lr)
    Set wsPvtTbl = Sheets("Sheet1")
    'wsPvtTbl.Cells.Clear
    For Each PvtTbl In wsPvtTbl.PivotTables
        'PvtTbl.TableRange2.Clear
    Next PvtTbl
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rng, _
    Version:=xlPivotTableVersion12).CreatePivotTable tabledestination:=wsPvtTbl.Range("D6"), _
    TableName:="PivotTable1", defaultversion:=xlPivotTableVersion12
    
    Set PvtTbl = wsPvtTbl.PivotTables("PivotTable1")
    wsPvtTbl.Select
        With PvtTbl.PivotFields("Invoiced By")
            .Orientation = xlRowField
            .Position = 1
            .Subtotals(1) = False
        End With
        
        With PvtTbl.PivotFields("Gross Profit")
            .Orientation = xlDataField
            .Function = xlSum
            .Position = 1
        End With
        With PvtTbl.PivotFields("Gross Profit")
            .Orientation = xlDataField
            .Function = xlSum
            .Position = 2
        End With
        
        With PvtTbl.PivotFields("MTD Gross")
            .Orientation = xlDataField
            .Function = xlSum
            .Position = 3
        End With
        
            With PvtTbl
            .RowAxisLayout xlTabularRow
        End With
    Pvtlr = wsPvtTbl.Cells(Rows.Count, 1).End(xlUp).Row
    
    With Range("D7:G7")
        .Interior.ColorIndex = 1
        .Font.ColorIndex = 2
        .Font.Size = 12
        .Font.Bold = True
    End With
    'With Range("D" & Pvtlr & ":D" & Pvtlr)
     '   .Interior.ColorIndex = 2
      '  .Font.ColorIndex = 2
    'End With
    
    wsPvtTbl.Columns.AutoFit
    Range("D1").Select
    Application.ScreenUpdating = True
    
        With ActiveSheet.UsedRange
            .Cells.Copy
            .Cells.PasteSpecial xlPasteValues
            .Cells(1).Select
        End With
        
        Rows(5).Delete
        
        Application.CutCopyMode = False
    
    MsgBox "Report has been created successfully."
    
    
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    09-15-2014
    Location
    london
    MS-Off Ver
    2013
    Posts
    111

    Re: How to sort rows in sheet1 by using the predefined order of locations specified in she

    Please help me with code for above

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need to sort/group locations in sheet1 based on order criteria provided in sheet4
    By aleanboy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2014, 03:30 PM
  2. What is this formula implying ?(Sheet1:Sheet4!B1) and a question about excel
    By bunnyfrostr in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-05-2014, 10:54 PM
  3. Formatting data input in order to use predefined macro
    By padrald0w in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2013, 06:00 AM
  4. Sort data to match a predefined list order
    By Neil0782 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-12-2012, 08:53 AM
  5. Matching names from sheet2, sheet3, sheet4 with names in sheet1
    By Lynx2x in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-28-2012, 07:51 AM

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