A
Alice
I am new to the VBA programming & I am trying to develop a VBA script
which will create charts (as a separate worksheet) for each worksheet
in a workbook.
Sub drill()
For i = 1 To Sheets.Count
Sheets("Sheet(i)").Select
Range("A8:I12").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet(i)").Range( _
"A8:I12"), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Oxygen
Chart"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Oxygen Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "US
Average"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Amount
Serviced"
End With
ActiveChart.ChartArea.Select
ActiveWindow.Zoom = 100
ActiveChart.Axes(xlValue).Select
Selection.TickLabels.NumberFormat = "$#,##0_);[Red]($#,##0)"
Sheets("Sheet(i)").Select
Range("A7").Select
Next i
End Sub
I get the error 'Subscript out of Range' Error.
If you can provide any hint to teh solution it will be of great help.
Also, if you have any suggestion of a good book/ resource for VBA,
please let me know.
Thanks,
Alice
which will create charts (as a separate worksheet) for each worksheet
in a workbook.
Sub drill()
For i = 1 To Sheets.Count
Sheets("Sheet(i)").Select
Range("A8:I12").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet(i)").Range( _
"A8:I12"), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Oxygen
Chart"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Oxygen Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "US
Average"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Amount
Serviced"
End With
ActiveChart.ChartArea.Select
ActiveWindow.Zoom = 100
ActiveChart.Axes(xlValue).Select
Selection.TickLabels.NumberFormat = "$#,##0_);[Red]($#,##0)"
Sheets("Sheet(i)").Select
Range("A7").Select
Next i
End Sub
I get the error 'Subscript out of Range' Error.
If you can provide any hint to teh solution it will be of great help.
Also, if you have any suggestion of a good book/ resource for VBA,
please let me know.
Thanks,
Alice