title: How do I make an Excel chart x-axis dynamic based on checkbox selection
body: <p>I have a chart on Sheet1, showing prices of an apple across different markets, drawing data from Sheet2. List of countries are on the x-axis. Price points are on the y-axis.</p>
  <p>Sheet1 also has a list of checkboxes (Sheet 1: S18:S34) for user to select which markets they would like to view. These checkboxes are linked to Sheet2: K29:K45.</p>
  <p>To make this work, I am trying to get Sheet2 to hide the rows of the non-selected markets, so that the chart only shows data of the selected markets.</p>
  <p>My attempt:</p>
  <p><strong>Sheet1:</strong></p>
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  
  'To activate MarketsSelection macro once checkboxes are changed
  
  If Not Intersect(Target, Range(&quot;S18:S34&quot;)) Is Nothing Then
  
      Call MarketsSelection
      
  End If
      
  End Sub
  </code></pre>
  <p><strong>To update Sheet2:</strong></p>
  <pre><code>Sub MarketsSelection()
  
  ' To unhide all rows first
  
      Sheets(&quot;Sheet2&quot;).Select
      Rows(&quot;29:45&quot;).Select
      Selection.EntireRow.Hidden = False
  
  ' To hide markets not chosen
  
      Application.ScreenUpdating = False
      Application.Calculation = xlManual
      For Each c In Range(&quot;K29:K45&quot;)
       If c.Value = &quot;&quot; Then Rows(c.Row).Hidden = True
      Next
      Application.Calculation = xlAutomatic
      Application.ScreenUpdating = True
  
      Sheets(&quot;Sheet1&quot;).Select
      
  End Sub
  </code></pre>
  <p>However, the above are not working for me. Any advice on change of code/method is highly appreciated!</p>
  <p><a href="https://i.stack.imgur.com/oIiuC.png" rel="nofollow noreferrer">Concept of Sheet 1</a></p>
  <p><a href="https://i.stack.imgur.com/4slSR.png" rel="nofollow noreferrer">Concept of Sheet 2</a></p>