6 month data on a graph

Goose0310

New Member
Joined
Mar 15, 2019
Messages
1
Hi! I have a VBA question.

I have a bar graph showing the the number of sales every month for the last 5 months.
For example: 1000 in Oct, 1200 in Nov, 1300 in Dec, 950 in Jan, and 800 in Feb

The Months are in One row (Row A), the number of sales are in another row (Row B).

Next month, I want to show the number of sales for (Nov, Dec, Jan, Feb, March) on the graph. The month after, it would shift again (Dec, Jan, Feb, March, April) and so on

And then keep on repeating that as months go by (looping)

How would I code that loop on VBA?
Or is there an easier way?

Thanks for the help!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,

I think it might be easier if you use Named Ranges.

For example, for Oct'18-Mar'19, your current Bar Chart would use two named ranges:
1. "dates" = A1:A6
2. "values" = B1:B6

Your goal is to shift these ranges automatically by one row, once a new month begins (Apr'19). In order to achieve that, you need to modify your named ranges to use INDEX formulas:
1. "dates" -> =INDEX($A:$A,COUNT($A:$A)-5):INDEX($A:$A,COUNT($A:$A))
2. "values" -> =INDEX($B:$B,COUNT($B:$B)-5):INDEX($B:$B,COUNT($B:$B))

Hope it helps. Let me know if anything is unclear.
 
Upvote 0

Forum statistics

Threads
1,214,887
Messages
6,122,095
Members
449,064
Latest member
Danger_SF

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