Reputation: 1
I'm trying to use a variable to define a portion of a range of cells in VBA. In the code below, I pre-defined the counter
and would like that to be the row number of the end portion of the range.
ActiveChart.FullSeriesCollection(1).XValues = "$A$2:$A&counter"
For example, if the counter were 5, the range would be $A$2:$A$5. But the counter changes. This doesn't compile and I'm stuck. Can anyone help?
Upvotes: 0
Views: 97
Reputation: 37460
You need to concatenate strings, which in VBA is done with &
operator.
How to concatenate strings in VBA
So, you need to use:
ActiveChart.FullSeriesCollection(1).XValues = "$A$2:$A" & counter
Upvotes: 3