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.
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:
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:
With this method, we can also swap two adjoining rows or columns.
Quickly swap contents of two cells or ranges in Excel:
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 SwapTwoRange() 'Updateby20131120 Dim Rng1 As Range, Rng2 As Range Dim arr1 As Variant, arr2 As Variant xTitleId = "KutoolsforExcel" Set Rng1 = Application.Selection Set Rng1 = Application.InputBox("Range1:", xTitleId, Rng1.Address, Type:=8) Set Rng2 = Application.InputBox("Range2:", xTitleId, Type:=8) Application.ScreenUpdating = False arr1 = Rng1.Value arr2 = Rng2.Value Rng1.Value = arr2 Rng2.Value = arr1 Application.ScreenUpdating = True End Sub
3. Then click button to run the code, then a dialog is displayed for you to select the two cells you want to swap between. See screenshots:
4. Click Ok in the popped-up dialog, the two selected cells are swapped. See screenshots:
Notes: This VBA code can’t swap the formatting of the two cells.
With Kutools for Excel's Swap Ranges utility, we not only can swap two adjoining cells, rows or columns, but also can switch two nonadjacent cells, rows or columns easily.
Before applying Kutools for Excel, please download and install it firstly.
1. Click Kutools > Range > Swap Ranges, see screenshot:
2. In the Swap Ranges dialog box, you need to:
- (1) click the first button in the Swap Range 1 box to select the cells that you like to swap.
- (2) click the second button from Swap Range 2 box to select the cells you will swap with.
Tips: You can select the two ranges before applying the feature, then you can see the selected two ranges are displayed in the Swap Range 1 and Swap Range 2 boxes separately.
- (3) Click the OK button.
Then two selected cells or ranges are swapped immediately. See screenshots:
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
- To post as a guest, your comment is unpublished.· 2 years agoKoje njesra... na kraju cu ipak raditi copy paste... Umesto da su ubacili swap opciju na padajucem menju....
- To post as a guest, your comment is unpublished.· 5 years agoCool trick that saved me a lot of time. Thank you!
- To post as a guest, your comment is unpublished.· 5 years agoFirst option work well for me thanks for your efforts... :-)
- To post as a guest, your comment is unpublished.· 5 years agoThanks !! works perfectly for me..
- To post as a guest, your comment is unpublished.· 6 years agoThanks !! works perfectly for me..
- To post as a guest, your comment is unpublished.· 6 years agoThank you for the information!!!
- To post as a guest, your comment is unpublished.· 6 years agoYou could just cut (non-adjacent) Cell A into an unoccupied cell, paste required cell B into that space then put A into the cell B formerly occupied couldn't you?
- To post as a guest, your comment is unpublished.· 5 years agoIt's not as simple as you suggested when cells have formula in them. And this also helps in inserting multiple cells at any desired location as well.
- To post as a guest, your comment is unpublished.· 6 years agoYes you could, but why go such a roundabout way when you can do it much faster this way.
Thanks ExtendOffice for your good work.