PDA

View Full Version : [SOLVED] Extend Datalabel Range



Olwa
06-21-2017, 01:25 AM
Hi there,

is it possible to extend the range of a data lable for a charts data series by coding?
Current situation: Im using a userform to create a new row of data in sheet 2 (not shown here) and extend the charts range by one like this:


lindex = 2
Do Until Sheets(2).Cells(lindex, 1).Value = ""
lindex = lindex + 1
Loop

[...]

Sheets(3).ChartObjects("Diagramm 1").Activate
ActiveChart.SetSourceData Source:=Range("'Chart_Data'!A2:C" & lindex)

This works just fine; my problem however is, that the data lable is taken from a range of cells that is not included within the charts range (A2:C & lindex) but (D2:D20). As soon as im creating a new set of data, the charts range is extended to (in this case) A2:C21 while the lable still shows (D2:D20), resulting in a bar without label. Is it possible to solve this (pref. Code?, cause im having trouble with including collumn D into the chart without messing it up).

Tried something like this:


ActiveChart.DataTable Source:=Range("'Chart_Data'!D2:D" & lindex)

Doesnt seem to be a legit syntax though, haha. It was just a guess.
Greetings

Bob Phillips
06-21-2017, 04:28 AM
Does this work for you?


ActiveChart.FullSeriesCollection(1).XValues = "=Chart_Data!$D$2:$D$" & lindex

Olwa
06-21-2017, 04:29 AM
Well, the solution was a simple as mindless. I could just manually extend the data labels range to (D2:D1000) and it does the trick as i wont add more than 20~ sets of data and the excessive ones dont show.