VBA: Dynamic Chart Range dependent on Last Row

jaspalsd

Board Regular
Joined
Feb 3, 2014
Messages
72
Hi,

I've put together a macro with a range of data where the lastrow has been defined.

All is well for the "table" - officially not a table but when I rerun the macro and set the range for the chart it goes to a completely different row

The last row should be row7 - above "TOTAL" and it works fine when rerunning the data for the table but I have no idea why it goes down to Row 27 for the chart.

Using this method
Code:
ActiveChart.SetSourceData _
    Source:=.Range("B2" & LastRow  & ":D2" & LastRow )

I could delete the chart with each time the macro is run but then I'll have to amend the formatting in the macro but I could do it this way instead!

I will appreciate any feedback and suggestions on how to fix this :)


XOe74xj.jpg
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
no worries

workaround is to make it as a table with spacing for the total row then hide the open row

pie chart range will always look at the table and automatically update the range
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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