SWAP Values Using Macros (VBA) in Excel Office 365 – [with Example]
Tags: swapvaluesusingmacro, vbamacros
Published: 2020-09-22 05:10:57

---
title: SWAP Values Using Macros (VBA) in Excel Office 365 – [with Example]
published: true
date: 2020-09-21 12:17:30 UTC
tags: SWAPValuesUsingMacro,VBAMacros
canonical_url: https://geekexcel.com/swap-values-using-macros-vba-in-excel-office-365-with-example/
---

## SWAP Values Using Macros in Excel:

In this article, we are going to see how to **Swap Values using Macros in Excel Office 365** with an example. Let’s get into this article!! Get an official version of **MS Excel** from the following link: [https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)

## Steps to Swap Values Using Macros in Excel:

To swap two values in the Excel spreadsheet with the help of Macros, do as below instructions.

- First, you need to enter two numbers that you want to swap.

![Enter two numbers](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/1-82.png)<figcaption id="caption-attachment-14392">Enter two numbers</figcaption>

- On the **Developer** Tab, **click** the **Insert** option, then **select** the **button** icon under the **ActiveX**  **controls** section.

![Select the button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/2-77.png)<figcaption id="caption-attachment-14394">Select the button</figcaption>

- Now, you need to **drag** and **select** the cell anywhere in the spreadsheet to **insert** the **button**.

![Insert button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/3-38.png)<figcaption id="caption-attachment-14395">Insert button</figcaption>

- You need to **right-click** on the button and **select** the **View**  **Code** option from the menu.

![Select View Code option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/4-16.png)<figcaption id="caption-attachment-14398">Select View Code option</figcaption>

- You have to enter the below code and close the window.

VBA Code for SWAP Values

Dim container As Double

container = Range(“A8”).Value

Range(“A8”).Value = Range(“B8”).Value

Range(“B8”).Value = container

![Enter the Code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/5-8.png)<figcaption id="caption-attachment-14399">Enter the Code</figcaption>

- Now, you need to check that the Design Mode is selected or not. If is selected, you have to deselect it.

![Deselect the Design Mode option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/6-6.png)<figcaption id="caption-attachment-14400">Deselect the Design Mode option</figcaption>

- You have to click the created button and see that the values are swapped.

![Result](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/7-4.png)<figcaption id="caption-attachment-14401">Result</figcaption>

From the above steps, you can clearly understand how to swap two numbers using Macros.

You can find the working of above Macro in the below video.

<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]--><video id="video-14387-1" width="694" height="470" preload="metadata" controls="controls"><source type="video/mp4" src="https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/video.mp4?_=1"></source><a href="https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/video.mp4">https://geekexcel.com/wp-content/uploads/2020/09/video.mp4</a></video>

## Wind-Up:

In this article, you can learn the steps to **Swap Values using Macros in Excel Office 365** with an example. Drop your **feedback** in the comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!!