Originally Posted by
lucas
Can you clean up a copy of it and post it? Why do you say a named range solution wouldn't work?
Hi Lucas thank you for replying. The reason I don?t use name ranges in this situation because I get a REF!# errors in the Define Name Box when I copy the worksheet to another workbook. I use a code to consolidate various workbooks into one master workbook and allot of these workbooks contains charts and when using name ranges I'm getting errors in the Define Name Box.
Well I finally figured it out how to get this to work of course I'm not a master in VBA it took me awhile but here?s what I got and it seems to work. I left a small sample file below with a macro named "test". Please let me know if I left something out.
Sub test()
'Choose the worksheet that contains the chart
Sheets("1st Shift").Select
'Excel names your chart so to be sure do a macro recording
'and select the chart and stop recording then look at the
'recording and it will tell you the name of your chart
ActiveSheet.ChartObjects("Chart 37").Activate
'Define your ranges in the source box of your charts
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Values = Range(Sheets("Table").[F20], Sheets("Table").[F65536].End(xlUp)) ' Values:
ActiveChart.SeriesCollection(1).XValues = Range(Sheets("Table").[E20], Sheets("Table").[E65536].End(xlUp)) 'Category Lables:
'Deselect your chart
ActiveWindow.Visible = False
'Name of your workbook
Windows("Sample Test.xls").Activate
End Sub
Thank You for the link Justinlabenne.