跳到主要內容

如何在Excel中的行或列之間交換內容?

有時,當我們使用工作表時,我們需要交換行或列。 例如,我想將A列與D列交換,想到的第一件事是使用複制和粘貼命令。 實際上,除了複製和粘貼外,還有其他一些方法可以解決此問題。

使用VBA代碼交換行或列

使用Kutools for Excel快速方便地交換行或列

使用Kutools for Excel將數據從行轉移到多列


1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊 窗口。

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。 然後點擊 按鈕運行代碼,會彈出一個對話框,供您選擇要交換的兩個範圍,請參見屏幕截圖:

doc交換行列01 01
1
doc交換行列02 02

4。 點擊後 Ok,兩個範圍被交換。 查看屏幕截圖:

doc交換行列01 01 2 doc交換行列02 02

對於Excel的初學者來說,代碼可能很困難,有沒有一種簡單的方法可以快速,省時地進行操作。 當然,Kutools for Excel可以幫助您快速而舒適地交換行或列。

Excel的Kutools : 帶有300多個便捷的Excel加載項,可以在30天內免費試用

如果你已經安裝 Excel的Kutools,您可以快速交換兩列或兩行。

1. 點擊 庫工具 > 範圍 > 互換範圍,請看截圖:

2.交換範圍 對話框,單擊  來自的按鈕 互換範圍1 選擇要交換的列A,然後單擊  來自的按鈕 互換範圍2 選擇列D.( 注意:交換範圍的大小必須相同。)

doc交換行列02 02

3。 然後點擊 OK。 兩列已被交換,單元格格式也被交換。 查看屏幕截圖:

doc交換行列01 01 2 doc交換行列02 02

有了這個 交換範圍的實用程序,您不僅可以交換行或列,還可以交換兩個範圍的內容。 單擊此處了解有關此功能的更多信息.

立即下載和免費試用Excel的Kutools!



在Excel工作表中快速將數據從行轉移到多列:

這款獨特的敏感免洗唇膜採用 Moisture WrapTM 技術和 Berry Mix ComplexTM 成分, Excel的Kutools變換範圍 功能,您可以快速將數據從一行或一列轉置為多行或一列,反之亦然。

doc轉置數據

Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!


Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!

相關文章:

如何快速交換Excel中兩個單元格的內容?

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (7)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
EXCELENTE, ni me perdí, gracias por su aporte
Rated 5 out of 5
This comment was minimized by the moderator on the site
Okk is there any way we can create a MACRO for it to do it fast bcz it won't be possible everytime to copy that code from somewhere and put it out there to Swap that Rows and Columns .
This comment was minimized by the moderator on the site
or you can just hold the shift key and drag the column where you want it to go
This comment was minimized by the moderator on the site
I've tried the VBA code solution. It seemed to work fine until now. In the range i swap, there is a URL cell (i.e. hyperlink). Although the swap looks ok, the hyperlinks are not updated. It still points to the URL of the original range. Is there any code patch to handle this? thank you.
This comment was minimized by the moderator on the site
Learn how to spell. Ridiculous. Emial. Really?
This comment was minimized by the moderator on the site
Please learn how to spell before posting on the web.
This comment was minimized by the moderator on the site
So in short, there is no built-in way to swap columns. Fail :)
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations