Swap cell contents in Excel?
From: http://www.extendoffice.com/documents/excel/860-excel-swap-contents-of-two-cells.html
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:
Select the cell you want to swap. In this example, select cell A4.
Press Shift key, and put the cursor at the right border.
Then drag the cursor to the right border of cell B4.
When there displays “工”, release the mouse.
And the two cell contents have been swapped.
With this method, we can also swap two adjoining rows or columns.
For the specific case of adjacent same-size rectangular ranges, you can use the method described in this answer to a similar question.
- Select the right or bottom range
- Press Ctrl+X
- Select the adjacent range (i.e., directly above or to the left)
- Press Ctrl++ (the
+
is usually above the=
key so this translates to Ctrl+Shift+=)
Note you can use the same procedure to swap whole adjacent rows or columns.
By easy, I mean either a keyboard shortcut or menu item, without involving copying to temporary cells or writing VBA scripts or anything like that. I'm looking for a way to just select two cells and click some menu item or press some key combination that will swap their contents.
Why impose this restriction? Creating a macro makes this trivial. As far as I know, it can't be done any other way. You can assign the macro to a button or hotkey.
Sub Swap()
If Selection.Count <> 2 Then
MsgBox "Select 2 cells (only) to swap."
Exit Sub
End If
Set trange = Selection
If trange.Areas.Count = 2 Then
temp = trange.Areas(2)
trange.Areas(2) = trange.Areas(1)
trange.Areas(1) = temp
Else
temp = trange(1)
trange(1) = trange(2)
trange(2) = temp
End If
End Sub