Does anyone know how to write the VBA code to make Series?
I have this data:
6 3
2 1 Start
6 3
4 5
5 7
4 8
7 12 End
6 10
12 8
9 10 Start
6 4
7 6
4 7
3 8 End
6 5
2 9
How do I build a macro to make Series chart for each Start-End block?
Here's my code but it does not work:
Option Explicit
Sub test()
Dim CellAddr As String
Dim Cell_1 As String
Dim Cell_2 As String
While ActiveCell.Offset(0, -2).Value > 0 'activecell is col C
If ActiveCell.Offset(0, 0).Value = "START" Then
Cell_1 = ActiveCell.Offset(0, 1).Address
End If
If ActiveCell.Offset(0, 0).Value = "END" Then
Cell_2 = ActiveCell.Offset(0, 2).Address
End If
ActiveCell.Offset(1, 0).Select
Wend
CellAddr = "Cell_1: Cell_2"
Range(CellAddr).Select
Charts.Add
ActiveChart.ChartType = xlAreaStacked
ActiveChart.SetSourceData Source:=Sheets("Chart"
.Range(CellAddr), PlotBy _:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Chart"
End Sub
I am learning Excel VBA. Please help.
Thanks,
XT
I have this data:
6 3
2 1 Start
6 3
4 5
5 7
4 8
7 12 End
6 10
12 8
9 10 Start
6 4
7 6
4 7
3 8 End
6 5
2 9
How do I build a macro to make Series chart for each Start-End block?
Here's my code but it does not work:
Option Explicit
Sub test()
Dim CellAddr As String
Dim Cell_1 As String
Dim Cell_2 As String
While ActiveCell.Offset(0, -2).Value > 0 'activecell is col C
If ActiveCell.Offset(0, 0).Value = "START" Then
Cell_1 = ActiveCell.Offset(0, 1).Address
End If
If ActiveCell.Offset(0, 0).Value = "END" Then
Cell_2 = ActiveCell.Offset(0, 2).Address
End If
ActiveCell.Offset(1, 0).Select
Wend
CellAddr = "Cell_1: Cell_2"
Range(CellAddr).Select
Charts.Add
ActiveChart.ChartType = xlAreaStacked
ActiveChart.SetSourceData Source:=Sheets("Chart"
ActiveChart.Location Where:=xlLocationAsObject, Name:="Chart"
End Sub
I am learning Excel VBA. Please help.
Thanks,
XT