dynamic adressing for Chart Data

Damakkus

New Member
Joined
Sep 15, 2011
Messages
1
Hi,
I am new to this forum. I am struggeling with creating multiple charts from one set of data in Excel using VBA.
I am able to create my first correct charts by:
Code:
Set chtChart = Charts.Add
            With chtChart
                .Name = "ANA_" & Counter1
                .ChartType = xlXYScatterLinesNoMarkers
                .SetSourceData Source:=Range("='Sheet1'!$E$3:$E$24"), _
                   PlotBy:=xlColumns
                .HasTitle = True
                .ChartTitle.Text = "=ANA_" & Counter1
                .Axes(xlCategory, xlPrimary).HasTitle = True
                .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X-Axis"
                .Axes(xlValue, xlPrimary).HasTitle = True
                .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y-Axis"
            End With
            MsgBox "Pause"
            ActiveChart.SeriesCollection(1).XValues = "='Sheet1'!$A$4:$A$24"
            'Adding new Series
            
            With ActiveChart.SeriesCollection.NewSeries
                .Name = Sheets("Sheet1").Range("F3")
                .Values = Sheets("Sheet1").Range("F4:F24")
                .XValues = Sheets("Sheet1").Range("'Sheet1'!A4:A24")
            End With
Now I would like to replace the hardcoded address-ranges (i.e. "='Sheet1'!$E$3:$E$24") by a dynamic address. At the time my current location on Sheet1 is E3.
For other commands I was able to replace it by:
Range(Selection, Selection.Offset(lastitem-3, 0))

This causes an error message.
Any help would be highly appreciated.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top