Swapping Two Cells

Written by Allen Wyatt (last updated February 6, 2023)
This tip applies to Excel 2007, 2010, 2013, and 2016


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

Searching for Paragraph Marks and Line Breaks

Word allows you to search not for special characters that normally do not print such as paragraph marks and line breaks.

Discover More

Converting to Automatic Endnotes

When you add endnotes to a document, they are automatically maintained and renumbered by Word, as necessary. If you get a ...

Discover More

Ignoring the Spelling of Proper Nouns

Proper nouns (such as the names of people) are routinely marked as incorrect by Word's spell checker. If you are tired of ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

AutoFilling Numbers with a Trailing Period

The AutoFill tool is very handy when it comes to quickly filling cells with a sequence of values. Sometimes, however, it ...

Discover More

Pasting Excel Data within Word's Page Margins

The programs in the Microsoft Office suite are designed to work with each other easily. Sometimes there can be hiccups ...

Discover More

Dates Copied Incorrectly

Under the right circumstances, you may notice problems when copying dates from one workbook to another. This tip explains ...

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}] (all 7 characters, in the sequence shown) 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 six minus 6?

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.