Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88054

Unwanted extra columns/series in excel VBA

$
0
0

I want to plot a chart in excel with clustered columns. The data (mean values) for the chart are already calculated in one table on the sheet, which is not always at the same position, so the offset is used.

When I run the code some additional columns/series are created with the data from the other parts of the sheet. Unfortunately I have no idea from where they come from. The number of additional columns is dependent from the location of the active cell. I will be very thankful for a solution.

The picture of additional columns/series:

chart

The code that I use:

Dim lc As Range
Set lc = Range("l2")

Dim cht As Object
Set cht = ActiveSheet.Shapes.AddChart
cht.Chart.ChartType = xlColumnClustered

cht.Chart.SeriesCollection(1).Name = Range(lc.Offset(0, 1), lc.Offset(0, 1))
cht.Chart.SeriesCollection(1).Values = Range(lc.Offset(2, 1), lc.Offset(2, 2))
cht.Chart.SeriesCollection(1).XValues = Range(lc.Offset(1, 1), lc.Offset(1, 2))

cht.Chart.SeriesCollection(2).Name = Range(lc.Offset(0, 3), lc.Offset(0, 3)) '"=sort7b!$M$10"
cht.Chart.SeriesCollection(2).Values = Range(lc.Offset(2, 3), lc.Offset(2, 4))
cht.Chart.SeriesCollection(2).XValues = Range(lc.Offset(1, 1), lc.Offset(1, 2))

Viewing all articles
Browse latest Browse all 88054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>