Swapping Two Cells

Written by Allen Wyatt (last updated July 22, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

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, 2016, 2019, Excel in Microsoft 365, and 2021.

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

Setting Spell-Checking Options

Like many things in Word, you can configure the way the spelling checker does its job. If you want to exercise more ...

Discover More

Progression Indicator in a Macro

When your macro is humming along, minding its own business, a user watching the screen may not see any activity and ...

Discover More

Disabling Shift Key Use when Opening a Workbook

Open up a workbook, and Excel normally runs the macros associated with that workbook. You can disable the automatic ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Getting Rid of Non-Printing Characters Intelligently

Is your worksheet, imported from an external source, plagued by non-printing characters that show up like small boxes ...

Discover More

Sequentially Inputting Information

When entering data in a worksheet, you may only want to add information to the cells in a particular range. You can ...

Discover More

Using AutoComplete with Disjointed Lists

AutoComplete can help you to more quickly enter information in a worksheet. How it works, behind the scenes, can affect ...

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 five more than 3?

2023-07-22 11:36:48

J. Woolley

My Excel Toolbox includes the SwapTwoCells macro to swap any two cells selected using Ctrl+Left-click. The macro uses Copy/Paste with Paste options (see Figure 1 below) . It supports both Undo (Ctrl+Z) and Redo/Repeat (Ctrl+Y). You can run it using the shortcut Ctrl+Shift+S.
See https://sites.google.com/view/MyExcelToolbox/

Figure 1. 


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.