Did you ever needed to swap values from one cell to another? Do you know how it is possible in Excel? Don’t worry if you want to do this and don’t know the process because in this tutorial I will tell you complete process with step by step by using Macros in Excel. In addition you will also get some programming along the tutorial.
Before following the procedure of this tutorial make sure you have enabled the Excel’s Developer Tab.
STEP 1: firstly follow this to start creating you button:
Go to Developer > Insert > ActiveX Controls > Button
Now in the Excel spread-sheet, drag anywhere to get a new button.
STEP 2: In second step select View Code option by right clicking on your new button which you have created in your first step.
STEP 3: Now you have open up a view code so here type this code:
Dim container As Double
container = Range(“A2”).Value
Range(“A2”).Value = Range(“B2”).Value
Range(“B2”).Value = container
Explanation of each code line is written below:
- Dim container As Double
This code line will help you to create a new variable named which will be named as container inside that you can store a numerical value and double type shows that it can also have a numerical value.
- container = Range(“A2”).Value
By this step in Cell A2 you are getting the first value and it will store it in your container variable.
- Range(“A2”).Value = Range(“B2”).Value
Now you have to copy the content of Cell B2 so that it can get paste into Cell A2. Just after completing this; both will be having the value 500 in this given example.
- Range(“B2”).Value = container
In the last lined step copy and paste the content of the container variable into Cell B2 so that the swap can be completed.