Сводные элементы, оставленные при группировании - PullRequest
0 голосов
/ 15 мая 2018

Я нуб VBA и смиренно нуждаюсь в помощи. Я позаимствовал код, предназначенный для группировки определенных основных элементов. Код работает отлично по большей части, но он пропускает 2 основных элемента, выделенных в коде ниже, которые принадлежат (согласно коду) определенной созданной группе. Я приложил код и снимок экрана. Пожалуйста, помогите.

Спасибо.

Dim itm2 As PivotItem
Dim unionrng2 As Range
Dim rLabel2 As Range

For Each itm2 In 
ActiveSheet.PivotTables("PivotTable1").PivotFields("Processor").PivotItems
If (itm2.Name = "Credit Card - Benefit Lifestyle" Or itm2.Name = "Credit 
Card - Benefits Dental" Or itm2.Name = "Credit Card - Benefits Eye" Or 
itm2.Name = "Credit Card - Benefits Lab1 22" Or itm2.Name = "Credit Card - 
Benefits Lab2" Or itm2.Name = "Credit Card - Benefits Save 2" Or itm2.Name = 
"Credit Card - Benefits Save 72" Or itm2.Name = "Credit Card - NMI CH Dental 
2" Or itm2.Name = "Credit Card - NMI CH Eye savings 16" Or itm2.Name = 
"Credit Card - NMI Q1" Or itm2.Name = "Credit Card - NMI Q2" Or itm2.Name 
= "Credit Card - NMI Q3" **<"This one is left out of the group"** Or 
itm2.Name = "Credit Card - NMI Q4") Then
        Set rLabel2 = itm2.LabelRange
        On Error GoTo 0
        If Not rLabel2 Is Nothing Then
            If unionrng2 Is Nothing Then
                Set unionrng2 = rLabel2
            Else
                Set unionrng2 = Union(unionrng2, rLabel2)
            End If
        End If
    End If
Next itm2
unionrng2.Group

Dim itm5 As PivotItem
Dim unionrng5 As Range
Dim rLabel5 As Range

For Each itm5 In 
ActiveSheet.PivotTables("PivotTable1").PivotFields("Processor").PivotItems
    If (itm5.Name = "ACH - AMC Chase 40 (Authorize)" Or itm5.Name = "ACH - 
C&H All (2967)" **<"This one is left out of the group"** Or itm5.Name = "ACH 
- C&H Discount Medical (2992)" Or 
itm5.Name = "ACH - Dental (3342)" Or itm5.Name = "ACH - Lab 1 (3339)" Or 
itm5.Name = "ACH - Lab 2 (3340)" Or itm5.Name = "ACH - Platinum Plus (3341)" 
Or itm5.Name = "ACH - Premier (3343)" Or itm5.Name = "ACH - Vision Benefits 
(3338)") Then
        Set rLabel5 = itm5.LabelRange
        On Error GoTo 0
        If Not rLabel5 Is Nothing Then
            If unionrng5 Is Nothing Then
                Set unionrng5 = rLabel5
            Else
                Set unionrng5 = Union(unionrng5, rLabel5)
            End If
        End If
    End If
Next itm5
unionrng5.Group

Снимок экрана проблемы

Screen shot of problem

...