Hi excelactuary,
Working with Excel Charts always seems more challenging than it should be, unless the 'Chart Wizard' does what you want.
See the following code in Ordinary Code module ModChartCopy that is included in the attached sample file:
It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
This option requires all variables to be declared and will give a compiler error for undeclared variables.
Notes:
a. Charts for 'January' are created/deleted for Software Development purposes only.
b. You can have any number of Charts of any type on Sheet 'January'.
c. Two charts arbitrarily exist on Sheet 'January'.
d. Data for both Charts is arbitrarily in 'A24:D26 (must preexist on each sheet in the same range)'.
e. Each Sheet Name (formula) is arbitrarily stored in cell 'C20' (must preexist on each sheet in the same cell)'.
f. Chart Title formulas are arbitrarily in cells 'A21' and 'A22' (must preexist on each sheet in the same range)'.
g. Macro CopyAllChartsOnSheetJanuaryToSheetsFebruaryThruDecember() deletes existing Charts on Sheet 'February' thru 'December'
and then copies all charts to Sheets 'February' thru 'December' .
Formulas for the 'Title' and 'Data Series' are adjusted on Sheets 'February' thru 'December' .
Months 'May' thru 'December' purposely do not exist in this workbook.
Data for 'Harry' is different on all sheets to verify that reference changes work properly.
Lewis
Bookmarks