jlgenualdi
New Member
- Joined
- Apr 25, 2012
- Messages
- 3
I spent a good portion of my work day today trying to figure this out and am still stumped -
I need to write a VBA macro to overlay multiple transparent rectangles on a chart to highlight different sections of data based on date ranges that span across the x-axis.
For instance, a chart may span from April 2011 thru April 2012. The users of the macro can specify a few sets of date ranges, such as:
01-Jun-2011 thru 15-Jul-2011;
15-Jul-2011 thru 15-Aug-2011;
01-Sep-2011 thru 30-Sep-2011
When they click the macro button, three rectangles should be drawn to capture the data within these 3 ranges. The top and bottom coordinates will always be the same and can be hard-coded. The part I am struggling with is how to determine the horizontal (x) coordinates to plot for the start and end of the rectangles. When hardcoded, one of the rectangles is plotted with the line of code below -
ActiveChart.Shapes.AddShape(msoShapeRectangle, 10, 27, 97, 200).Select
I need to determine what values should be plugged in where I have 10 and 97 above dynamically based on the data source values that match up with the selected date range.
I was looking at the Chart.GetChartElement method, but that seems to perform sort of the reverse of what I need to do here.
Any help would be greatly appreciated!
I need to write a VBA macro to overlay multiple transparent rectangles on a chart to highlight different sections of data based on date ranges that span across the x-axis.
For instance, a chart may span from April 2011 thru April 2012. The users of the macro can specify a few sets of date ranges, such as:
01-Jun-2011 thru 15-Jul-2011;
15-Jul-2011 thru 15-Aug-2011;
01-Sep-2011 thru 30-Sep-2011
When they click the macro button, three rectangles should be drawn to capture the data within these 3 ranges. The top and bottom coordinates will always be the same and can be hard-coded. The part I am struggling with is how to determine the horizontal (x) coordinates to plot for the start and end of the rectangles. When hardcoded, one of the rectangles is plotted with the line of code below -
ActiveChart.Shapes.AddShape(msoShapeRectangle, 10, 27, 97, 200).Select
I need to determine what values should be plugged in where I have 10 and 97 above dynamically based on the data source values that match up with the selected date range.
I was looking at the Chart.GetChartElement method, but that seems to perform sort of the reverse of what I need to do here.
Any help would be greatly appreciated!