Method 1 – Swapping Two Adjacent Cells Manually
- Select the cell that you want to swap.
- Move the cursor to the upper or lower side of the cell until it changes to a four-headed arrow.
- Press the Shift key and drag the cursor to the left side of the cell with which cell to swap.
- Release the cursor when a green symbol like the letter “I” appears.
You can see the cell contents are swapped.
You can swap the whole range by selecting and then dragging them to the left while pressing the shift key.
Method 2 – Swapping Non-Adjacent Cells with VBA
Step 1: Insert VBA code
- Go to the Developer tab > Visual Basic from the Code group.
- Click on the Insert tab > Module.
- Type the code below in the Module window:
Sub Swap_Two_Cells() Dim Rg1 As Range, Rg2 As Range Dim Arr1 As Variant, Arr2 As Variant xTitleId = "Microsoft Excel" Set Rg1 = Application.Selection Set Rg1 = Application.InputBox("Range 1:", xTitleId, Rg1.Address, Type:=8) Set Rg2 = Application.InputBox("Range 2:", xTitleId, Type:=8) Application.ScreenUpdating = False Arr1 = Rg1.Value Arr2 = Rg2.Value Rg1.Value = Arr2 Rg2.Value = Arr1 Application.ScreenUpdating = True End Sub
- Save the code and close the window.
Step 2: Run VBA Code
- Go to the Developer tab > Macros.
- Select the code name and press the Run button.
Step 3: Insert Cell Ranges to Swap
- In the first input box:
- Select the range of cells to swap.
- Click OK.
- In the second input box:
- Select the range of cells to swap with.
- Click OK.
You will be able to swap cell contents of non-adjacent cells.
Download Practice Workbook
You can download the practice workbook from here.
Frequently Asked Questions
How to Reverse Text of a Cell in Excel?
You can do it using the following formula with the TEXTJOIN function: =TEXTJOIN("",TRUE,MID(A1,SEQUENCE(,LEN(A1),LEN(A1),-1),1))
How Do You Swap Rows in Excel?
To swap rows in Excel:
- Select an entire row.
- Press Alt + Shift + Up or Down arrow keys.
Can I Swap Text Based on a Specific Condition in Excel?
Yes, you can use more advanced techniques like Excel functions or VBA (Visual Basic for Applications) to swap text based on specific conditions.
Related Article
<< Go Back to Excel Cells | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!