Moving charts using a macro

Frankie needs HELP

New Member
Joined
Apr 3, 2002
Messages
43
I've produced a macro that creates a chart but I can't get it to go where I want it on my spreadsheet. I need to produce another macro that puts it two rows under my Analysis Table (the lines in the table may alter but the chart mut always remain two rows underneath). The chart should also occupy 25 rows of the sheet and go inbetween columns A to D.

Can anyone help???
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Frankie,

Since you are adding rows to the worksheet, I assume you know the row number of the last row. This being the case, you can use the following code to position your chart two rows below this last row index (LastRow):

Dim iRow As Integer
iRow = LastRow + 2
Dim C As ChartObject
Set C = ActiveSheet.ChartObjects("Chart 3")
C.Top = Cells(iRow, 1).Top
C.Height = Cells(iRow + 25, 1).Top - C.Top
C.Left = 0
C.Width = [d1].Left - C.Left

This code refers to the chart by name. If you haven't named your chart, or you aren't sure what its name is (my example assumed "Chart 3") select your chart using Ctrl-Click with the mouse, and look at the Name box just above the top-left cell on the worksheet.

Also, from your description I assumed you wanted the chart to span columns A through C.
 
Upvote 0
I'm a little bit stuck on the line that I have to enter the last row, it keeps coming up with an error. My last row is 34. Do I have to have LastRow in the code?

Also what if the data changes, and there are more rows. Row 34 might not be the last row? Can this be made variable?

HELP!
 
Upvote 0
I've produced a macro that creates a chart but I can't get it to go where I want it on my spreadsheet. I need to produce another macro that puts it two rows under my Analysis Table (in row 34 but the lines in the table may alter but the chart must always remain two rows underneath). The chart should also occupy 25 rows of the sheet and go from columns A to D.

Can anyone help???
 
Upvote 0
You could insert the following at the beginning
Range("a65533").End(xlUp).Select
LastrRow = ActiveCell.Row()
 
Upvote 0
Hi again Frankie,

Yes, SAMS is exactly right. Thanks SAMS. If you put that in front of the code I posted that should work.

It could be shortened a bit by incorporating it directly into my code:

Dim iRow As Long
iRow = [a65526].End(xlUp).Row + 2
Dim C As ChartObject
Set C = ActiveSheet.ChartObjects("Chart 3")
C.Top = Cells(iRow, 1).Top
C.Height = Cells(iRow + 25, 1).Top - C.Top
C.Left = 0
C.Width = [d1].Left - C.Left

Happy charting.

Damon
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

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