title: Excel Macro to create graphs for distinct values
body: <p>Hello I am working in Excel on data sheet with ~25000 rows. Each row has a column for product code, date and weight. I would like to create a macro that generates a scatter plot of the weights for each product code (date on the x-axis, weight on the y-axis). I have the data sorted by product code and also have a 4th column that identifies when a row has a new product code from the one before.</p>
  
  <p><a href="https://i.stack.imgur.com/IiU52.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IiU52.png" alt="enter image description here"></a></p>
  
  <p>I have recorded a macro where I create a single graph for a product code but I am unsure how to modify it so that it can go through the entire worksheet and group the rows with the same code and create a graph for each.</p>
  
  <p>I have included a screenshot of my data. This is the code for the recorded macro: </p>
  
  <pre><code>Sub Macro1()
  '
  ' Macro1 Macro
  ' graph
  '
  ' Keyboard Shortcut: Ctrl+g
  '
      Range("B12:B19,D12:D19").Select
      Range("D12").Activate
      Charts.Add2
      ActiveChart.SetSourceData Source:=Range( _
          "'Cleaned Up'!$B$12:$B$19,'Cleaned Up'!$D$12:$D$19")
      ActiveChart.ChartType = xlXYScatter
      Sheets("Cleaned Up").Select
  End Sub
  </code></pre>
  
  <p>Thanks in advance for any help!</p>