title: How to make multiple PivotItems visible in Excel VBA
body: <p>I have a Pivot table in sheet "Main". In <code>PivotField</code> "Report Filter" I have "Country Code" which contain 200 countries. I want to Make visible more than 1 countries from that filter using InputBox. </p>
  
  <p>The problem is I need to choose minimum one country or ALL in filter manually and run this program. I can't get the correct data by doing this. 
  I need to deselect all the countries and then I need to run.</p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>Sub Addcountries()
  
  Dim ws As Worksheet
  Dim str1 As Variant
  Dim Data As Variant
  Dim pf As PivotField
  Dim target As PivotTable
  
  Set ws = Sheets("Main")
  str1 = Application.InputBox("Enter the Country - comma separated")
  
  If str1 = False Then
      MsgBox "Please Enter one Country", , "Filter Country"
      Exit Sub
  Else
      If InStr(1, str1, ",") &gt; 0 Then
          Data = Split(str1, ",")
          For i = LBound(Data) To UBound(Data)
              ws.PivotTables("MainTable").PivotFields("Country Code").PivotItems(Data(i)).Visible = True
          Next i
      Else
          ws.PivotTables("MainTable").PivotFields("Country Code").PivotItems(str1).Visible = True
      End If
  End If
  
  End Sub       
  </code></pre>