Skip to main content

How to swap contents between rows or columns in Excel?

Author: Tech Support Last Modified: 2024-10-25

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

Transpose data from rows to multiple columns with Kutools for Excel


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()
'Updateby Extendoffice
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 Run button button to run the code, a dialog is popped out for you to select the two ranges you want to swap with, see screenshots:

A screenshot of the first range selection dialog box
Arrow
A screenshot of the second range selection dialog

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

A screenshot showing selected cells before swapping Arrow A screenshot showing swapped cells

Swap rows or columns quickly and conveniently with Kutools for Excel

The code may be 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 offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Itegarate with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

If you have installed Kutools for Excel, you can swap two columns or rows quickly.

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

A screenshot of Kutools Swap Ranges option in the Excel Ribbon

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

A screenshot of the Swap Ranges dialog

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

A screenshot showing columns before using Kutools Arrow A screenshot showing columns after using Kutools

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

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now

Demo: Swap rows or columns quickly with Kutools for Excel

Kutools for Excel: Over 300 handy tools at your fingertips! Enjoy permanently free AI features! Download Now!

Transpose data from rows to multiple columns with Kutools for Excel

With Kutools for Excel’s Transform Range feature, you can quickly transpose the data from one row or column to multiple rows or columns and vice versa.

A screenshot showing the Transpose Range dialog and options for transposing data from rows to multiple columns


Related article:

How to quickly swap contents of two cells in Excel?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!