Charting Range

yanclarechen

New Member
Joined
Aug 7, 2002
Messages
17
I have an Excel spreadsheet set up to collect shipping data on weekly basis. I also set up a bar chart to show the weekly shipment graphically. But I only want 14 weeks'data to show up on my bar chart, ie. starting from the current week, count back 14 weeks and update the bar chart. Or in another word, every week when I add the previous week's shipment data to the spreadsheet, I want the chart to be automatically updated, with the lastest week's data bar being added and the oldest bar being deleted. Is there any function or VBA code can be use to achieve that?
my email address: yanclarechen@lucent.com
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Upvote 0
Hi yanclarechen,

It does not require VBA to do this. You can use a Dynamic Named Range to automatically adjust the range to include the last 14 cells as you add or subtract data. Then you can use this range in defining your chart series.

For example, suppose your x values (dates?) are in column A starting in A2 and y values (shipment data) are in column B starting in B2. First use Insert > Define > Name to define a name (say, MyYdata) and in the Refers To box enter

=OFFSET(Sheet1!$B$2,COUNT(Sheet1!$B:$B)-15,0,14,1)

Similarly for your x data define a name (say, MyXdata) and in the Refers To box enter

=OFFSET(MyYdata,0,-1)

which simply offsets from the MyXdata one column to the left.

Now select your data series on the Chart and in the formula bar replace the x and y series data references with the new Dynamic Named Ranges, like this:

=SERIES(,Sheet1!MyXdata,Sheet1!MyYData,1)

Now you will find that as you add or delete data at the ends of the two ranges, the chart automatically adjusts to show exactly 14 weeks of data.
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,414
Members
448,895
Latest member
omarahmed1

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