How do I make a graph fill a specific range? I found out how to do it using VBA a while ago, but I can’t for the life of me find out how to do it again. I’d like a graph to fill a specific range, like F1 to K8. That way if the other columns to the left change due to user input, the graph while still stay in that range, making everything look nice.
My second questions is, how do I change the size of the markers on an excel graph using VBA? I’m plotting thousands of data points, and the default markers are huge diamonds, so the graph looks ridiculous with thousands of these. The line is just this incredibly thick thing.
And one extra bonus question! I’m making the entire graph using VBA. There are two series I’m making. However, when inserting the two series, it adds a third series with no data points in it. It wouldn’t be annoying if it didn’t show up in the legend. How do I delete a series?
Thank you! Here is the relevant code. Counter and NewTracker are variables that are based on user input. I believe Counter = 13 and NewTracker = 1202 for the data I’m using, but I don’t think it matters based on my questions here! Just replace the ranges with something nicer if you feel like using an example. 🙂
Sub Makingthechart()
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatter
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "=Sheet1!$B$1"
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!$A$2:$A$" & Counter + 1
ActiveChart.SeriesCollection(1).Values = "=Sheet1!$B$2:$B$" & Counter + 1
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "CFL Calculated"
ActiveChart.SeriesCollection(2).XValues = "=Sheet1!$XFB$1:$XFB$" & NewTracker
ActiveChart.SeriesCollection(2).Values = "=Sheet1!$XFC$1:$XFC$" & NewTracker
With ActiveWorkbook.ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "CFL Over Time"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time (Days)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "CFL"
.Axes(xlCategory).HasMajorGridlines = True
.Axes(xlCategory).HasMinorGridlines = True
End With
End Sub
I seriously appreciate all of your help! You guys are the reason I’ve been pretty successful in my internship so far! I can’t believe you guys know all these tiny things about VBA that I can’t even find via Google.
1 Answer