Skip to main content
 

Quickly swap contents of two cells or ranges in Excel

Author: Xiaoyang Last Modified: 2024-07-15

Swapping the contents of two cells or ranges in Excel is a common requirement when reorganizing data, adjusting layouts, or correcting entry errors. This guide will introduce three methods to quickly and efficiently swap contents in Excel, enabling you to modify your data without extensive cutting and pasting, which can save time and reduce the risk of errors.

Manually swap two adjoining cell contents
Easily swap contents of two cells or ranges with only several clicks
Swap two cell contents with VBA code


Manually swap two adjoining cell contents

Occasionally, you may find yourself needing to swap two adjoining cells. This can be done manually without much effort. Below are the steps to swap cells A4 and B4, as shown in the screenshots:

doc-swap-cells1

  1. Select one of the cell to swap: For instance, select cell A4.
  2. Hold down the Shift key and position your cursor on the right border of the selected cell.
  3. Carefully drag the cursor to the right border of cell B4.
  4. Once the cursor displays a "" symbol, release the mouse.

The contents of the two cells should now be swapped, as depicted in the screenshot below.

doc-swap-cells2


Easily swap contents of two cells or ranges with only several clicks

For those who need to swap non-adjoining cells or ranges, using an Excel add-in like Kutools for Excel can simplify the process significantly.

Before applying Kutools for Excel, please download and install it firstly.

After installing Kutools for Excel, select Kutools > Range > Swap Ranges to open the Swap Ranges dialog box, and then configure as follows.

  1. In the Swap Range 1 section, select the first cell or range you want to swap.
  2. In the Swap Range 2 section, select the second cell or range you want to swap with.
    Tips: For ease, you can pre-select the two ranges before opening the Swap Ranges dialog. The pre-selected ranges will automatically appear in the "Swap Range 1" and "Swap Range 2" boxes respectively.
  3. Click the OK button.
Result

Then two selected cells or ranges are swapped immediately. See screenshots:

doc swap ranges1

  If you want to have a free trial (30-day) of this utility, please click to download it, and then go to apply the operation according above steps.


Swap two nonadjacent cell contents with VBA code

When the two cells are nonadjacent, the above method will not work. We can swap them with VBA code.

1. Press the Ctrl key and select the two nonadjacent cells you want to swap.

2. Click Developer>Visual Basic, a new Microsoft Visual Basic for applications window will be displayed, click Insert>Module, and input the following code into the Module:

Sub SwapTwoRange()
'Updateby20131120
Dim Rng1 As Range, Rng2 As Range
Dim arr1 As Variant, arr2 As Variant
xTitleId = "KutoolsforExcel"
Set Rng1 = Application.Selection
Set Rng1 = Application.InputBox("Range1:", xTitleId, Rng1.Address, Type:=8)
Set Rng2 = Application.InputBox("Range2:", xTitleId, Type:=8)
Application.ScreenUpdating = False
arr1 = Rng1.Value
arr2 = Rng2.Value
Rng1.Value = arr2
Rng2.Value = arr1
Application.ScreenUpdating = True
End Sub

3. Then click doc-multiply-calculation-3 button to run the code, then a dialog is displayed for you to select the two cells you want to swap between. See screenshots:

doc swap ranges1

4. Click Ok in the popped-up dialog, the two selected cells are swapped. See screenshots:

doc swap ranges1

Notes: This VBA code can’t swap the formatting of the two cells.


Demo: Swap two random cell contents with Kutools for Excel


Related article:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!