title: How to copy visible pivot item data to a cell in Excel VBA
body: <p><a href="https://i.stack.imgur.com/1BDQ3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1BDQ3.png" alt="enter image description here"></a></p>
  
  <p>I have country code in pivot report filter. I would like to get the visible piviot item data and place each values in each cell from A1. I used the code below. But All the cell showing only last value in filter. I need to move automatically from A1 .Help me</p>
  
  <pre><code>Sub Getpivotitem()
  
  Dim ws As Worksheet
  Dim str1 As Variant
  Dim Data As Variant
  Dim rng As Range
  
  Set rng = Range("A1:X1")
  Set ws = Sheets("Sheet1")
  
  Dim pi As PivotItem
  For Each pi In ws.PivotTables("PivotTable1").PivotFields("Country Code").PivotItems
      If pi.Visible = True Then
          For Each cell In rng.Columns
          cell.Value = pi
          Next cell
       End If
  Next pi
  
  End Sub
  </code></pre>