Using a variable for worksheet name in SERIES

R

reynoldscm

Hi,
I am trying to reference a dynamic range in my code that modifies a
existing chart SERIES statement. However, whenever I enter the dynami
range name (i.e. rngACWP) Excel inserts the workbook file name i
addition. I have tried referencing the sheet name...which didn't work
and then tried to establish a variable that referenced th
ActiveWorkbook name but don't think I did right. So, I basically hav
two questions:
1. Is there a way to utilize some sort of variable in the SERIE
statement so that the user isn't limited to a filename that I creat
for them but dynamically pulls their filename to use in the formula?
2. If the above anwer is yes, how would I define the variable an
utilize it in the SERIES statement?

Here is the snippet of code I am working with:
ActiveSheet.ChartObjects("CUM Chart").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(3).Select
ActiveChart.SeriesCollection(3).Formula = _
"=SERIES('RangeData'!R1C4,'Automated CSPR Charts -down to
buttons.xls'!'rngDate','Automated CSPR Charts -down to
buttons.xls'!'rngACWP',3)"

Thanks for the help.
Chri


-
reynoldsc
 
J

Jon Peltier

Chris -

As usual, Excel provides several ways to skin this cat, and not all are
so efficient.

I usually find it more reliable to edit the components of the series
formula directly, rather than build a new formula. Something like this:

With ActiveChart.SeriesCollection(3)
.Values = worksheets("RangeData").Range("rngACWP")
.XValues = worksheets("RangeData").Range("rngDate")
End With

Although I just noticed that this changed the name to the static
address. Try this:

With ActiveChart.SeriesCollection(3)
.Values = "='" & worksheets("RangeData").Name & "'!" & "rngACWP"
.XValues = "='" & worksheets("RangeData").Name & "'!" & "rngDate"
End With

If the name is a workbook level name, Excel changes the sheet name
prefix to the workbook name. If it is a worksheet level name, then Excel
leaves the sheet name intact.

- Jon
 
Top