Setting Chart Position using Macros (VBA) in Excel Office 365!
Tags: settingchartposition, vbamacros, macrosvba
Published: 2021-03-10 04:08:23

---
title: Setting Chart Position using Macros (VBA) in Excel Office 365!
published: true
date: 2021-03-09 11:28:32 UTC
tags: Settingchartposition,VBAMacros,MacrosVBA
canonical_url: https://geekexcel.com/setting-chart-position-using-macros-vba-in-excel-office-365/
---

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](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_kynaEFNOIi.png)<figcaption id="caption-attachment-22368">Select the chart</figcaption>

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

![Select Visual Basic option](https://geekexcel.com/wp-content/uploads/2020/09/Select-Visual-Basic-option-4.png)<figcaption id="caption-attachment-14755">Select the Visual Basic option</figcaption>

- 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](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_x0fVfARLzT.png)<figcaption id="caption-attachment-22369">Save the code</figcaption>

- 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](https://geekexcel.com/wp-content/uploads/2020/09/Choose-the-Macros-option-2.png)<figcaption id="caption-attachment-14747">Choose the Macros option</figcaption>

- You need to make sure that your macro is selected and **click** the **Run** button.

![Click the Run button](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_o97GXwf5hd.png)<figcaption id="caption-attachment-22370">Click the Run button</figcaption>

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

![Output](https://geekexcel.com/wp-content/uploads/2021/03/EXCEL_piwim0KpMp.png)<figcaption id="caption-attachment-22372">Output</figcaption>

## 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.](https://geekexcel.com/)** Keep Learning!

#### Read Ahead:

- [How to Rename Multiple Files using Macros (VBA) in Excel 365?](https://geekexcel.com/how-to-rename-multiple-files-using-macros-vba-in-excel-365/)
- [Split Data into Multiple Worksheets with Set of Rows using Macros (VBA) in Excel!!](https://geekexcel.com/split-data-into-multiple-worksheets-with-set-of-rows-using-macros-vba-in-excel/)
- [Hide Rows with Zero Value using Macros (VBA) in Excel Office 365!](https://geekexcel.com/hide-rows-with-zero-value-using-macros-vba-in-excel-office-365/)