PDA

View Full Version : If Pivot Item = "" then skip



jazz2409
02-20-2020, 06:47 AM
Hello, is there a way to skip a Pivot Item? The code below originally from p45cal creates a table for each item in the filter. However if there's a blank item or "" then it creates an unnecessary table. Here's the code:


'Create tables on the right from the pivot table: Set Destn1 = NewSht.Cells(Rows.Count, "P").End(xlUp).Offset(2)
With pt
If pf1.CurrentPage.Name = CurrentCat Then
For Each pit In pf.PivotItems

With Destn1
.Value = CurrentCat & " Agents " & pit.Name
With .Font
.Name = "Calibri"
.Size = 11
.Underline = xlUnderlineStyleSingle
.Bold = True
End With
End With
Set Destn1 = Destn1.Offset(2)
pf.ClearAllFilters 'added this line (makes it a bit more robust).
pf.CurrentPage = pit.Name
With .TableRange1
.Copy
'Destn1.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Destn1.PasteSpecial Paste:=xlPasteAll
Application.CutCopyMode = False
Set myTable = NewSht.ListObjects.Add(xlSrcRange, Destn1.Resize(.Rows.Count, .Columns.Count), , xlYes)
''myTable.TableStyle = "TableStyleMedium14"
myTable.ShowTableStyleRowStripes = False
'mytable.DataBodyRange.Cells.HorizontalAlignment = xlCenter
myTable.HeaderRowRange.Cells.HorizontalAlignment = xlCenter

Set Destn1 = Destn1.Offset(.Rows.Count + 2)
End With '.TableRange1
myTable.Unlist
Next pit
End If
End With 'PT




How do I prevent it from doing that?

Thank you :)