Pivot Table Grouping Question

mayoung

Active Member
Joined
Mar 26, 2014
Messages
259
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
In the pivot table below in the column A there are several rows that start with WTY SUBM and a date. Is there away to group those all together in one row based on WTY SUBM?
This pivot table was created using VBA code so if we could take this step further what would be the code to do this? Would be interested in know how to do this if there is away with or without VBA? Any help would be greatly appreciated, Thanks in Advance.

DataminerFile.xml
ABCDEF
25SHOP NOT HERE77
26SHOP SERV11
27SHOP WAIT CUST1313
28SHOP WAIT RNTL66
29SHOP WAIT SALES33
30SHOP WAIT SERV1515
31SHOP WAIT STOCK11
32WTY SUBM11
33WTY SUBM 02/2311
34WTY SUBM 03/0411
35WTY SUBM 03/0511
36WTY SUBM 03/2211
37WTY SUBM 03/2411
38WTY SUBM 03/2611
39WTY SUBM 04/0111
40WTY SUBM 04/0222
41WTY SUBM 04/14112
42WTY SUBM 04/15325
43WTY SUBM 04/2222
44WTY WAITING SUB12416
45Grand Total100120335339
46Sum of W/O TotalSalesperson
PivotTable
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe something like this:

VBA Code:
Sub Group_WTY()
    Dim rngGroup As Range
    Dim rngRow As Range
    Dim cll As Range
    Dim CaptionRowRange As String
    Dim strSearch As String
    Dim intSearchString As Integer
    
    CaptionRowRange = "Title" 'the caption of the first pivot field in the row section
    strSearch = "WTY SUBM"
    intSearchString = Len(strSearch)
    Set rngRow = ActiveSheet.PivotTables(1).rowrange
    For Each cll In rngRow
        If UCase(Left(cll, intSearchString)) = strSearch Then
            If rngGroup Is Nothing Then
                Set rngGroup = cll
            Else
                Set rngGroup = Union(rngGroup, cll)
            End If
        End If
    Next
    rngGroup.Group
    ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange & "2").ShowDetail = False
    ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange & "2").PivotItems("Group1").Caption = "WTY SUBM"
End Sub
 
Upvote 0
Solution
Maybe something like this:

VBA Code:
Sub Group_WTY()
    Dim rngGroup As Range
    Dim rngRow As Range
    Dim cll As Range
    Dim CaptionRowRange As String
    Dim strSearch As String
    Dim intSearchString As Integer
   
    CaptionRowRange = "Title" 'the caption of the first pivot field in the row section
    strSearch = "WTY SUBM"
    intSearchString = Len(strSearch)
    Set rngRow = ActiveSheet.PivotTables(1).rowrange
    For Each cll In rngRow
        If UCase(Left(cll, intSearchString)) = strSearch Then
            If rngGroup Is Nothing Then
                Set rngGroup = cll
            Else
                Set rngGroup = Union(rngGroup, cll)
            End If
        End If
    Next
    rngGroup.Group
    ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange & "2").ShowDetail = False
    ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange & "2").PivotItems("Group1").Caption = "WTY SUBM"
End Sub

mart37, Thanks for replying.

Code runs fine until it gets to the last two lines of code then I get a Run-Time Error:

ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange & "2").ShowDetail = False
ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange & "2").PivotItems("Group1").Caption = "WTY SUBM"

Run-Time Error '1004":

Unable to get the PivotFields Property of the PivotTable Class
 
Upvote 0
Did you change your fieldname in this line: CaptionRowRange = "Title"
 
Upvote 0
Did you change your fieldname in this line: CaptionRowRange = "Title"
Do you mean to try the code like this?

ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange = ‘Title’).ShowDetail = False
ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange = ‘Title’).PivotItems("Group1").Caption = "WTY SUBM"
 
Upvote 0
Do you mean to try the code like this?

ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange = ‘Title’).ShowDetail = False
ActiveSheet.PivotTables(1).PivotFields(CaptionRowRange = ‘Title’).PivotItems("Group1").Caption = "WTY SUBM"
I figured it out. Thanks
 
Upvote 0
mart37

One more question related to this?

What is had to two groups to " WTY SUBM " but also add "F/I DRD" is it possible to do two at once? If so how would you modify the code?

Thank You in advance...
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top