Swapping Two Cells

by Allen Wyatt
(last updated July 19, 2021)

9

Adam needs to swap the contents of two cells and wonders if there is a way to do it without doing a three-step move.

There are actually a few ways you can accomplish this task, depending on how the two cells are situated in relation to each other. If the two cells are adjacent, then you can use the mouse to make the swap:

Select the first cell (for instance, cell C3). Then, hold down the Shift key as you drag one of the cell edges over the cell you want to swap with (for instance, cell D3). This takes a bit of practice, but as you move the mouse pointer around the cell you want to swap with, you'll see "heavy" markers appear that indicate where where the swap will occur.

In reality, what is happening is that you are indicating where you want the original cell (C3) moved. Since you want to swap with cell D3, you want to continue holding down the Shift key until you see the heavy marker appear to the right of cell D3. (See Figure 1.)

Figure 1. The "heavy" marker indicates where the original cell will be copied.

Since the original cell is being moved to the right, cell D3 moves to the left to fill where cell C3 used to be. The result is that cells C3 and D3 are swapped.

If you don't want to use the mouse and keyboard together, you may find these steps just a bit easier:

  1. Select the right-most cell you want to swap (in this case, cell D3).
  2. Press Ctrl+X. This cuts the cell to the Clipboard, and you should see "marching ants" around cell D3.
  3. Select the left-most cell you want to swap (in this case, cell C3).
  4. Press Ctrl++ (that's Ctrl plus the plus sign, which is the same as pressing Shift+Ctrl+=).

A third way to swap adjacent cells is to select the two of them and then use the sorting capabilities of Excel to sort just the two selected cells. You may need to play with sorting ascending or descending, but you should be able to eventually get the cells in the order desired.

If your cells are not adjacent to each other, then you'll need to rely on a macro to do the swapping. The following macro will swap two non-adjacent cells or two adjacent cells; it doesn't matter.

Sub SwapCells()
    Dim sHolder As String

    If Selection.Cells.Count = 2 Then
        With Selection
            sHolder = .Cells(1).Formula
            If .Areas.Count = 2 Then  ' Cells selected using Ctrl key
                .Areas(1).Formula = .Areas(2).Formula
                .Areas(2).Formula = sHolder
            Else                      ' Adjacent cells are selected
                .Cells(1).Formula = .Cells(2).Formula
                .Cells(2).Formula = sHolder
            End If
        End With
    Else
        MsgBox "Select only TWO cells to swap", vbCritical
    End If
End Sub

Note that the macro only swaps what is in the cells, not cell formatting. (The earlier mouse and keyboard approaches for use with adjacent cells swapped formatting as well as cell contents.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (1664) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Checking All Cell Formatting in VBA

When your macro checks the formatting used for a cell, it needs to be careful that the type of formatting being checked ...

Discover More

Printing Workbook Properties

Want to create a printed record of the properties associated with a workbook? There is no easy way to do it in Excel. ...

Discover More

Comma-Delimited Differences for PC and Mac

When you choose to save worksheet data in CSV format, Excel gives you three choices for file formats. Those choices are ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Inserting Different Dashes

Excel supports several types of dashes. This tip describes those different types and explains how to enter them in a cell.

Discover More

Converting Forced Text to Numbers

If you have some numbers stored in cells that are formatted as text, you may get some surprises when you try to use those ...

Discover More

Moving Cells Using the Mouse

Want to easily move information from one cell to another? A quick way to do it is to simply drag and drop using the mouse.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 7?

2021-07-20 09:50:38

J. Woolley

@Andrew Evans
Thank you for noticing my previous comment (2018-11-25). The SwapTwoCells macro will swap any two cells selected with Ctrl+Click (or similar). The macro uses Copy/Paste with Paste options and support for Undo plus Redo/Repeat. I assigned the shortcut Ctrl+Shift+S to run it. The latest version dated June 2019 is available in My Excel Toolbox and the MyToolbox.xlam add-in file.
See https://sites.google.com/view/MyExcelToolbox/


2021-07-19 15:30:46

robert Lohman

I have been using CTRL + X to cut, then ALT +I+E to swap to new location , for years. Learned from Mr Excel in a Dueling Excel
Video.


2021-07-19 05:29:08

Andrew Evans

Interesting options - but even more interesting is the macro from Mr. J. Woolley. Always nice to see where someone takes an idea and improves on it.
What an excellent macro and thank you for sharing it with everyone - even available 3 years after publishing.


2018-11-25 12:32:48

J. Woolley

You might be interested in my SwapTwoCells macro to swap the cells in Selection using Copy/Paste with Paste options and support for Undo plus Redo/Repeat. I tried to upload the VBA here without success. (Code posted in comments here always gets mangled anyway.) You can view SwapTwoCells_VBA.txt here:
https://drive.google.com/file/d/1A44QpOcOpKSfKvltdGKnH3ue8my5xRPu/view


2018-10-26 17:59:58

F. NIÑO

Mr Allen, Excelent, other geniuses called gurus, many nuts a few fleas, you solved it very concretely, thank you very much on behalf of hundreds of busy netizens, many thanks, Bs. F.Niño


2018-07-23 00:25:11

Chris

The above macro for swapping two non adjacent cells does not work for me. I guess my case may be different. I want a macro that can compare a range of values say on column D to another range of values on column A.
If a cell on column D is blank, the macro does nothing to it.
If a value exists any where on Column D cell that is not equal to the adjacent value on column A cell, the macro then moves that value from column D cell up or down to where it equals a value on column A. Can macro of this sort be possible to build? Please help. My macro skill is very limited.
Column A usually has values ranging from about 1 to 5,000
Column D has about 200 values spread out within range 1 to 5,000 with some cells blank. I guess that's the reason swapping values could not work for me. Thank you. Chris


2017-05-28 19:41:44

Henry Noble

Method 1, Shift+Drag, appears to work equally well to the right or left and up or down.


2017-05-28 18:42:55

John Allott

You need to also consider if the cells have any dependent formulas. The manual system applies a CUT method, therefore, any references will remain.

The macro version is a COPY VALUES


2017-05-27 14:51:57

John Fistere

It is useful to know that the first method of swapping two cells (using mouse and keys) works for swapping a column of data, whether it be a specific length column or the entire spreadsheet column. It also works for rows of data.

John Fistere


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.