I am using Excel 2013 and I have a pivot table with hundreds of filter values that I need to iterate through, making each one visiible individually , then copy the filtered value, and a specific cell (non-Pivot, and IF >0) and paste it (values only) into a specified sheet and the move on to the next pivot item and do the same. I found some code that is similar to what I want
Sub PivotStockItems()
Dim i As Integer
Dim sItem As String
Application.ScreenUpdating = False
With ActiveSheet.PivotTables("PivotTable1")
.PivotCache.MissingItemsLimit = xlMissingItemsNone
.PivotCache.Refresh
With .PivotFields("Country")
'---hide all items except item 1
.PivotItems(1).Visible = True
For i = 2 To .PivotItems.Count
.PivotItems(i).Visible = False
Next
For i = 1 To .PivotItems.Count
.PivotItems(i).Visible = True
If i <> 1 Then .PivotItems(i - 1).Visible = False
sItem = .PivotItems(i)
Cells.Copy
Workbooks.Add
With ActiveWorkbook
.Sheets(1).Cells(1).PasteSpecial _
Paste:=xlPasteValuesAndNumberFormats
.SaveAs "C:\TEST\MyReport-" & sItem & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook
.Close
End With
Next i
End With
End With
End Sub However, I know I need to cut out
Cells.Copy
Workbooks.Add
With ActiveWorkbook
.Sheets(1).Cells(1).PasteSpecial _
Paste:=xlPasteValuesAndNumberFormats
.SaveAs "C:\TEST\MyReport-" & sItem & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook
.Close
I just do not know what to add to for the copying of a certain cell (non-Pivot) and pasting it into a different sheet assuming it meets the >0 criteria. I am relatively new to VBA and I am trying to improve my skills.
Adding Screenshots for Reference Essentially, I am wanting to iterate through B3 (Pivot Table) and copy B3 and F46 into the new sheet pictured below If F46>0. :
PivotTable
? or just a cell "riding" on the Pivot Table's value being filterred ? Range("A40:I47") is part of thePivotTable
? Is the cell you want to copy allways in "F46" ? – Shai Rado