How to quickly swap contents of two cells in Excel?

When we are handling a worksheet, we may need to swap the contents of two cells sometimes. Normally most of us just know “to cut, paste and copy” for swapping the contents, but it’s time-consuming. We are going to talk about how to quickly swap contents in cells in Excel.

Manually swap two adjoining cell contents

Swap two nonadjacent cell contents with VBA code

Swap two random cell contents with Kutools for Excel

Kutools for Excel: 120 Cool Tools and Advanced Features for Excel 2013, 2010 and 2007. Read more...
Office Tab: Enable Tabbed Editing and Browsing in Office, Just Like Chrome, Firefox, IE 8/9/10. Read more...
Classic Menu for Office: Bring Classic Menus and Toolbars of Office 2003/XP/2000 Back to Office 2007, 2010 and 2013. Read more...

arrow blue right bubble Manually swap two adjoining cell contents

Hot
Amazing! Using Tabs in Excel like Firefox, Chrome, Internet Explore 10!

Learn more Free download

Sometimes, there are two adjoining cells need to be swapped. We can manually do it easily. Look at the following screenshot, I want to swap cell A4 and B4, please do as follows:

doc-swap-cells1

1. Select the cell you want to swap. In this example, select cell A4.

2. Press Shift key, and put the cursor at the right border.

3. Then drag the cursor to the right border of cell B4.

4. When there displays “”, release the mouse.

5. And the two cell contents have been swapped. See screenshot:

doc-swap-cells2

With this method, we can also swap two adjoining rows or columns.


arrow blue right bubble 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 SwapSelections()
Dim sValue1 As Range, sValue2 As Range
Dim cValue1 As String, cValue2 As String
If Selection.Cells.Count > 2 Or Selection.Cells.Count < 2 Then
MsgBox "Your selection should only contain 2 cells"
End
End If
If Selection.Areas.Count > 1 Then
Set sValue1 = Selection.Areas(1).Cells(1, 1)
Set sValue2 = Selection.Areas(2).Cells(1, 1)
ElseIf Selection.Rows.Count > Selection.Columns.Count Then
Set sValue1 = Selection.Range("A1")
Set sValue2 = Selection.Range("A2")
Else
Set sValue1 = Selection.Range("A1")
Set sValue2 = Selection.Range("B1")
End If
cValue1 = sValue1
cValue2 = sValue2
sValue1 = cValue2
sValue2 = cValue1
End Sub

3. Then click doc-multiply-calculation-3 button to run the code, and the two cells have been swapped. See screenshots:

doc-swap-cells3 -2 doc-swap-cells4

Notes: 1. This VBA code only can swap two random cell contents, not two random selections.

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


arrow blue right bubble Swap two random cell contents with Kutools for Excel

With Kutools for Excel, we not only can swap two adjoining cells, rows or columns, but also can switch two nonadjacent cells, rows or columns.

Kutools for Excel: with more than 120 handy Excel add-ins, free to try with no limitation in 30 days. Get it Now.

After installing Kutools for Excel, you can do as the following steps:

1. Click Kutools > Range Converter > Swap Ranges, see screenshot:

doc-swap-cells5

2. In the Swap Ranges dialog box,click the first doc-replace-range-names-7 button from Swap Range 1 to select the cell that you like to swap, and then click the second doc-replace-range-names-7 button from Swap Range 2 to select the cell is swapped with. See screenshot:

doc-swap-cells6

3. Then click OK, and the two ranges have been swapped. See screenshots:

doc-swap-cells7 -2 doc-swap-cells8

If you want to know more about this feature, please visit Swap Ranges.


Related article:

How to swap rows or columns in Excel?


Kutools for Excel

More than 120 Advanced Functions for Excel 2013, 2010, 2007 and Office 365.

screen shot

btn read more     btn download     btn purchase