0% found this document useful (0 votes)
64 views

Setting Chart Position Using Macros (VBA) in Excel Office 365

This document provides steps to set the position of a chart in Excel using VBA macros. It explains selecting the chart, copying code to define the range the chart will be placed in, saving and running the macro. When run, the macro positions the chart in the specified range. The document aims to teach setting chart position programmatically in Excel.

Uploaded by

Raj Mathur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Setting Chart Position Using Macros (VBA) in Excel Office 365

This document provides steps to set the position of a chart in Excel using VBA macros. It explains selecting the chart, copying code to define the range the chart will be placed in, saving and running the macro. When run, the macro positions the chart in the specified range. The document aims to teach setting chart position programmatically in Excel.

Uploaded by

Raj Mathur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

In this article, you will learn the simple steps for 

setting chart position using Macros


(VBA) in Excel Office 365. If we insert a chart in the Excel spreadsheet, it will appear at a
random place. To generate a chat in the specified position, you need to follow the below-
given steps.
Setting Chart Position using Macros:
To insert a chart in the specified position, follow the below steps.
In the following image, you can see the example chart about student marks.
We are going to set the position of a chart in the spreadsheet as we wish.
To do this, you have to select the chart that you want to set position.

Select the chart


On the Developer Tab, select the Visual Basic option under the Code section.

Select the Visual Basic option


Then you need to copy and paste the code given below.
VBA code to set the chart position using Macros
Sub setChartPosition()
Dim x As Range
Dim xChart As ChartObject
Set x = Range (“G1:L10”)
Set xChart = ActiveSheet.ChartObjects(1)
.Top = x(1).Top
.Left = x(1).Left
.Width = x.Width
.Height = x.Height
End With
End Sub
You need to save the code by selecting it. Then close the window.

Save the code


You have to open the sheet containing the data. On the Developer Tab,
choose the Macros option in the Code section.
Choose the Macros option
You need to make sure that your macro is selected and click the Run button.

Click the Run button


At last, the chart is placed in the specified position as shown in the below image.

Output

Verdict:
In the above article, you can learn the simple steps for setting chart position using
Macros (VBA) in Excel Office 365. Kindly, share your feedback in the below comment
section. Thanks for visiting Geek Excel. Keep Learning!

You might also like