Hi,
I've just started using VBA. I have 18 worksheets with identical data in them ("FB1" to "FB18"). I want to be able to make a bunch of different graphs for each worksheet (the same graphs for each worksheet) and plot them in another worksheet called "Plots". It would be great to have a button with a list box (or some sort of drop down menu/selector) that allows me to control which worksheet i am creating graphs for (i have played around a bit with the combo box to no avail...) and that plots the graphs when clicked.
I have the code to plot the graphs i want for each worksheet.
Formula:
Sub Grapher()
'Grapher Macro
lastdatapoint = ActiveSheet.Range("B1").End(xlDown).Row
'********************************************************************************************
'Indoor Graph
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Range("'FB2'!$R$3:$R" & lastdatapoint)
ActiveChart.Legend.Select
ActiveChart.SeriesCollection(1).Name = "='FB2'!$R$1"
ActiveChart.SeriesCollection(1).XValues = "='FB2'!$B$3:$B" & lastdatapoint
'x axis label spacing
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).TickMarkSpacing = 10
ActiveChart.Axes(xlCategory).TickLabelSpacing = 10
ActiveChart.ChartArea.Select
'axes titles
With ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Temperature (C)"
End With
'make the graph area bigger
With ActiveChart.Parent
.Height = 325
.Width = 500
End With
' ********************************************************************************************
'Temperature Macro
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
.ChartType = xlLine
.SetSourceData Source:=Range("'FB2'!$ES$3:$ES" & lastdatapoint)
.PlotArea.Select
.SeriesCollection(1).Name = "='FB2'!$ES$1"
.SeriesCollection(1).XValues = "='FB2'!$B$3:$B" & lastdatapoint
.SeriesCollection.NewSeries
.SeriesCollection(2).Values = "='FB2'!$FC$3:$FC" & lastdatapoint
.SeriesCollection(2).Name = "='FB2'!$FC$1"
.SeriesCollection.NewSeries
.SeriesCollection(3).Values = "='FB2'!$FE$3:$FE" & lastdatapoint
.SeriesCollection(3).Name = "='FB2'!$FE$1"
.SeriesCollection.NewSeries
.SeriesCollection(4).Values = "='FB2'!$FG$3:$FG" & lastdatapoint
.SeriesCollection(4).Name = "='FB2'!$FG$1"
.HasTitle = True
.ChartTitle.Characters.Text = "Weather"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Temperature (C)"
End With
'x axis label spacing
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).TickMarkSpacing = 10
ActiveChart.Axes(xlCategory).TickLabelSpacing = 10
ActiveChart.ChartArea.Select
With ActiveChart.Parent
.Height = 325
.Width = 500
End With
End Sub
Thanks!
Dan
Bookmarks