(Solved) – Excel Macro to create graphs for distinct values


Hello I am working in Excel on data sheet with ~25000 rows. Each row has a column for (data screenshot) 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.

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.

I have included a screenshot of my data. This is the code for the recorded macro:

Sub Macro1()
' Macro1 Macro
' graph
' Keyboard Shortcut: Ctrl g
    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

Thanks in advance for any help!

Leave a Reply

Your email address will not be published. Required fields are marked *