yannezhang
02-20-2013, 09:55 AM
I am writing VBA code for an x-y chart using data from columns A and C. A provides data for x-axis, C for y-axis in the example below:
A B C
1 10 20
2 11 21
3 12 22
4 13 23
The following lines work correctly with the Range format:
With ActiveChart
.ChartType = xlXYScatterLines
SetSourceData Source:=Sheets("sorted").Range("a2:a5, c2:c5"), PlotBy:=xlColumns
End With
But I run into difficulty composing the same line with variables, i.e 2->FirstCell, 5->LastCell, and not include column B.
Things I've tried:
.SetSourceData Source:=Sheets("sorted").Range("a" & FirstCell, "c" & LastCell), PlotBy:=xlColumns
(This covers all columns A,B and C. But I want A and C only)
A B C
1 10 20
2 11 21
3 12 22
4 13 23
The following lines work correctly with the Range format:
With ActiveChart
.ChartType = xlXYScatterLines
SetSourceData Source:=Sheets("sorted").Range("a2:a5, c2:c5"), PlotBy:=xlColumns
End With
But I run into difficulty composing the same line with variables, i.e 2->FirstCell, 5->LastCell, and not include column B.
Things I've tried:
.SetSourceData Source:=Sheets("sorted").Range("a" & FirstCell, "c" & LastCell), PlotBy:=xlColumns
(This covers all columns A,B and C. But I want A and C only)