ExtendOffice - Professional Add-ins and Tools for Microsoft Office
fackbook twitter

How to swap rows or columns in Excel?

Sometimes, when we use a worksheet, we need to swap the rows or the columns. For example, I want to exchange column A with column D, the first thing that came to my mind is to use copy and paste command. In fact, except the copy and paste, there are some other methods to solve this problem.

Swap rows or columns with VBA code

swap rows or columns quickly and conveniently with Kutools for Excel


Swap two ranges without losing cell formatting:

With Kutools for Excel’s Swap Ranges feature, you can swap two selected cell ranges as quickly as you can.

doc swap rows columns 02 02


arrow blue right bubble Swap rows or columns with VBA code

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

Sub SwapTwoRange()
'Updateby20131113
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, a dialog is popped out for you to select the two ranges you want to swap with, see screenshots:

doc swap rows columns 01 01
 1
doc swap rows columns 02 02

4. After clicking Ok, the two ranges are swapped. See screenshots:

doc swap rows columns 01 01  2 doc swap rows columns 02 02

arrow blue right bubble swap rows or columns quickly and conveniently with Kutools for Excel

The code may be are difficult for starters of Excel, is there a simple way to do it quickly and time-saving. Of course, Kutools for Excel can help you swap rows or columns quickly and comfortably.

Kutools for Excel : with more than 120 handy Excel add-ins, free to try with no limitation in 60 days

If you have installed Kutools for Excel, you can swap two columns or rows quickly.( Free Download Kutools for Excel Now! )

1. Click Kutools > Range > Swap ranges,see screenshot:

doc swap rows columns 02 02

2. In the Swap Ranges dialog box, click  button from Swap Range 1 to select column A that you want to swap, and then click  button from Swap Range 2 to select column D.( Note: The ranges for swapping must be identical in the same size.)

doc swap rows columns 02 02

3. Then click OK. The two columns have been swapped and the cell formatting is swapped as well. See screenshots:

doc swap rows columns 01 01  2 doc swap rows columns 02 02

With this Swap Ranges utility, you are not only can swap rows or columns but also can swap contents of two ranges. Click here to know more about this feature.

Free Download Kutools for Excel Now!


Related article:

How to quickly swap contents of two cells in Excel?


Recommended Productivity Tools

Office Tab

gold star1 Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.

Kutools for Excel

gold star1 Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!

gold star1 200 New Features for Excel, Make Excel Much Easy and Powerful:

  • Merge Cell/Rows/Columns without Losing Data.
  • Combine and Consolidate Multiple Sheets and Workbooks.
  • Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
  • Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
  • More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

Screen shot of Kutools for Excel

btn read more      btn download     btn purchase

Add comment


Security code
Refresh