I'm sure there is a fairly simple answer to this question but I've been pulling my hair out for multiple days trying to figure this out and no one in my department works with VBA enough to know. I'm new to automating graphs but I have a project where I need to make almost 800 graphs! The data itself is fairly straightforward, with 4 variables (columns): County, City, Store Type, and Number of Employees:
COUNTY CITY STORE TYPE NUMBER OF EMPLOYEES
X A 1 100
X A 2 100
X A 3 100
X A 4 100
X B 1 100
X B 2 100
X B 3 100
X B 4 100
I need to make bar graphs for each County/City combination with the Store Type as the X-values and the Number of Employees displayed on the Y-axis. This is super easy to do in VBA:
Sub makegraph2()
Range("A2:D5").Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$A$2:$D$5")
ActiveChart.ChartTitle.Text = "Employees per Store Type"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Employees per Store
Type"
End Sub
Rather than copying/pasting the same graph and reselecting the data for each 4 rows downward, I'm trying to find a way to automate it with a loop. I've tried doing this myself (testing with only 50 rows ((A2:D50 represents all 4 columns and 50 rows)) so not to get 800 graphs that are wrong and crash my computer) using offset in many different ways. My most resent attempt produces a graph with all 50 rows on it at once:
Sub makegraph()
Dim Row As Integer
For Row = 1 To 50
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!A2:D50").Offset(4, 0)
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Employees by Store Type"
Next Row
End Sub
Before that, I made separate graphs but they were all of the same data (would not go down 4 rows to graph the next set). So clearly I'm using Offset and Range wrong, but I can't figure out how...
Any help is so appreciated!! Thank you!!