Creating a Pie Chart based on a Dynamic Range

Yeft

New Member
Joined
Jan 6, 2023
Messages
37
Office Version
  1. 365
Platform
  1. Windows
Hello There,

I'm a beginner in regards to VBA coding, and I'm wondering if some one can give me hand with a code as requested below:
I need to create a Pie Chart via VBA; based on a range that is updated Frequently, so the number of rows with Data may increase.
I need to insert that Chart so there will always be with an offset (number of rows below the Data range). There fore I can set up
the Print Area, and get it ready for printing. Please see example below:

1728048661130.png

Any help will be much appreciated.

Thanks,
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Not sure why you think you need vba for this. If it's because you need to insert a chart as part of an automated process, then this answer won't help you.

Base your chart on a named range (at the sheet level, IIRC ). Make that named range dynamic by using a formula in the named range dialog where it asks for the data range for the named range. I have done this with other chart styles but would have to go looking for the file, find the named range and copy the formula. Then you would have to alter it to suit your situation, so you might as well google how to create a dynamic range. I can't tell if your chart is based on fixed columns but dynamic rows or the other way around. My columns were fixed.
 
Upvote 0
HI Micron,

Thanks for your input. I'm looking for VBA cause I have an option button which activates a macro based on specific criteria, so it will populate all rows
with Data. The Columns are fixed, the rows are variable, as they may increase or decrease with Data.
If you think that it stills does not need VBA coding for the chart, please explain the easiest way.

Thank you,
 
Upvote 0
If I interpret that correctly, you can still use vba to populate a range - you just don't need vba to make the chart data source dynamic. I'm saying you can base the chart on a named range that is dynamic by defining a range formula, like this:
=OFFSET(DATA!$B$6,0,0,COUNTA(DATA!$B:$B),1)

That counts the rows in DATA sheet, column B that have data, beginning with B6. The chart changes according to how many rows have data in column B. If your code puts 50 rows in column B (or whatever you're using) the chart should end up being based on 50 rows. If 75 rows, then chart would be based on 75 rows.
1728317075712.png
 
Upvote 0
Solution
Yeft,

Please Note: In the future, when marking a post as the solution, please mark the post that contains the solution (not your own post acknowledging that some other post was the solution).
When a post is marked as the solution, it is then shown right underneath the original question so people viewing the question can easily see the question and solution in a single quick glance without having to hunt through all the posts.

I have updated this thread for you.
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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