Showing posts with label move. Show all posts
Showing posts with label move. Show all posts

Tuesday, October 13, 2015

How to move and resize an Excel chart or shape using a VBA macro

To move a chart to a specific cell or resize to be same as range:
Sub relocate()
Call move_chart_to_cell(Cells(1, 1))
Call resize_chart_same_as_range(Range("A1:E20"))
End Sub

Sub move_chart_to_cell(cell as range)
ActiveSheet.Shapes("MyChart").Left = cell.Left
ActiveSheet.Shapes("MyChart").Top = cell.Top
End Sub

Sub resize_chart_same_as_range(r as range)
ActiveSheet.Shapes("MyChart").Height = r.Height
ActiveSheet.Shapes("MyChart").Width = r.Width

End Sub

Before Macro run:



After Macro run:


Created by DoMyExcel.com © | Excel & VBA Consulting | Customized Excel Solutions starting at 29 USD
Services provided to Individuals and Businesses | Free Quote: DoMyExcel@gmail.com