Macro to Create a Chart Based on a Dynamic Range of Data

XcelMonkey

New Member
Joined
Feb 18, 2015
Messages
8
Hi,

I'll start off by mentioning that I'm very inexperienced when it comes to VBA, so this is may be quite simple.

I'm using Microsoft Excel 2013 and trying to make a macro that will create a chart based on a dynamic range of data. I have the macro written with all of my formats correct, and just need to make the range dynamic. I'll explain what I'm trying to do.

I have different hours of operation for each day of the week (Monday through Sunday), for each set of data that will be input into this template. I want my macro to create a chart, based on the hours of operation for a given day (e.g. Monday). The following is an example of what my data may look like for Monday:

2z99k5u.png


I want the graph that this macro creates to be based only off the hours that this chart has values for e.g. 1pm-8pm (or call it A4:B11)

My original thought was to use an OFFSET function, referencing the 12PM cell (A3), and have the array stretch 1 column to the right, and a variable number of rows down, based on the hours (of operation) value held in another cell (Below as "8" under "# hrs" )

al4yom.png


Note: I realized while trying to describe that my problem, that this would only solve the problem of determining the end of my array. I think I could implement a Match/Offset combination to solve this, but my formula would definitely get messy.

Now my problem is firstly that I'm sure there's a more efficient way to go about this - does anyone have a suggestion? If not, here's the line of code where I'm trying to input the previously stated function:

ActiveChart.FullSeriesCollection(1).Values = "=$A$3:OFFSET(G2,1)"

I'm well aware that there's probably a ton wrong with this line. To reiterate, I'm trying to create an array with the reference point "A3", extending "1" column to the right, and "G2" rows down.

This is my first post and I apologize if I'm not very clear.

Any help is greatly appreciated.

Thanks.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
That's great, thanks Derek.

I ended up turning the data into a table, and including a filter for sales ">0".
 
Upvote 0

Forum statistics

Threads
1,215,376
Messages
6,124,594
Members
449,174
Latest member
chandan4057

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