跳到主要內容

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

在處理工作表時,有時可能需要交換兩個單元格的內容。 通常,我們大多數人只知道“剪切,粘貼和復制”即可交換內容,但這很耗時。 我們將討論如何在Excel中快速交換內容。

手動交換兩個相鄰的單元格內容
用VBA代碼交換兩個不相鄰的單元格內容
只需單擊幾下即可輕鬆交換兩個隨機單元格內容


手動交換兩個相鄰的單元格內容

有時,需要交換兩個相鄰的單元格。 我們可以手動輕鬆地做到這一點。 看下面的屏幕截圖,我想交換單元格A4和B4,請執行以下操作:

文檔交換單元格1

1。 選擇要交換的單元格。 在此的示例中選擇單元格A4。

2。 按 轉移 鍵,然後將光標置於右邊框。

3。 然後將光標拖到單元格B4的右邊界。

4。 當顯示“”,鬆開鼠標。

5。 並且兩個單元格內容已交換。 看截圖:

文檔交換單元格2

使用此方法,我們還可以交換兩個相鄰的行或列。

在Excel中快速交換兩個單元格或範圍的內容:

Excel的Kutools's 交換範圍 實用程序可幫助您輕鬆地一次在Excel中交換兩個指定的單元格或範圍,如下面的演示所示。
立即下載並試用! (30 天免費試用)

交換單元1


用VBA代碼交換兩個不相鄰的單元格內容

當兩個單元格不相鄰時,上述方法將不起作用。 我們可以將它們替換為VBA代碼。

1。 按 按Ctrl 鍵,然後選擇要交換的兩個不相鄰的單元格。

2。 點擊 開發者 >Visual Basic中,一個新的 適用於應用程序的Microsoft Visual Basic 將顯示一個窗口,單擊 插入>模塊,然後將以下代碼輸入到 模塊:

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。 然後點擊 文檔乘法計算 3 按鈕運行代碼,然後顯示一個對話框供您選擇要在其間交換的兩個單元格。 查看屏幕截圖:

文檔交換範圍1

4。 點擊 Ok 在彈出的對話框中,兩個選定的單元被交換。 查看屏幕截圖:

文檔交換範圍1

筆記: 此VBA代碼無法交換兩個單元格的格式。


只需單擊幾下即可輕鬆交換兩個隨機單元格內容

這款獨特的敏感免洗唇膜採用 Moisture WrapTM 技術和 Berry Mix ComplexTM 成分, Excel的Kutools's 交換範圍 實用程序,我們不僅可以交換兩個相鄰的單元格,行或列,而且還可以輕鬆切換兩個不相鄰的單元格,行或列。

申請前 Excel的Kutools首先下載並安裝.

1。 點擊 庫工具 > 範圍 > 交換範圍,請參見屏幕截圖:

2。 在裡面 交換範圍 對話框,您需要:

  • (1)點擊第一個 文檔替換範圍名稱-7 按鈕在 互換範圍1 框以選擇要交換的單元格。
  • (2)點擊第二 文檔替換範圍名稱-7 來自的按鈕 互換範圍2 框以選擇要交換的單元格。
    保養竅門:您可以在應用功能之前選擇兩個範圍,然後可以看到所選的兩個範圍分別顯示在“交換範圍1”和“交換範圍2”框中。
  • (3)點擊 OK 按鈕。

然後,將立即交換兩個選定的單元格或範圍。 查看屏幕截圖:

文檔交換範圍1

  如果您想免費試用(30天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


演示:使用Kutools for 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 (12)
Rated 2.5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
The vba is pants because it loses formulas and formatting. It's incredible that Excel has been through like about 25 different versions and STILL doesn't have the facility in it natively to swap two ranges/non-adjacent cells around. Sort it out Microsoft!
Rated 2.5 out of 5
This comment was minimized by the moderator on the site
Legyenszíves Megírni melyik az a müszak gomb.
Köszönöm Üdv Ádám
This comment was minimized by the moderator on the site
this isn't working for me. I don't know why
This comment was minimized by the moderator on the site
Koje njesra... na kraju cu ipak raditi copy paste... Umesto da su ubacili swap opciju na padajucem menju....
This comment was minimized by the moderator on the site
Cool trick that saved me a lot of time. Thank you!
This comment was minimized by the moderator on the site
First option work well for me thanks for your efforts... :-)
This comment was minimized by the moderator on the site
Thanks !! works perfectly for me..
This comment was minimized by the moderator on the site
Thanks !! works perfectly for me..
This comment was minimized by the moderator on the site
Thank you for the information!!!
This comment was minimized by the moderator on the site
You 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?
This comment was minimized by the moderator on the site
It'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.
This comment was minimized by the moderator on the site
Yes you could, but why go such a roundabout way when you can do it much faster this way. Thanks ExtendOffice for your good work.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations