如何在Excel中快速合併具有相同數據的相鄰行?
假設您有一個工作表,在相鄰的行中有相同的數據,現在您想將相同的單元格合併到一個單元格中,以使數據看起來整潔美觀。 如何快速方便地合併具有相同數據的相鄰行? 今天,我將向您介紹一些解決此問題的快速方法。
使用VBA代碼合併同一數據的相鄰行
當然,您可以合併相同的數據 合併與中心 命令,但是如果有數百個單元需要合併,則此方法將很耗時。 因此,以下VBA代碼可以幫助您輕鬆合併相同的數據。
1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。
2。 點擊 插入 > 模塊,然後將以下宏粘貼到 模塊窗口。
Sub MergeSameCell()
'Updateby Extendoffice
Dim Rng As Range, xCell As Range
Dim xRows As Integer
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
xRows = WorkRng.Rows.Count
For Each Rng In WorkRng.Columns
For i = 1 To xRows - 1
For j = i + 1 To xRows
If Rng.Cells(i, 1).Value <> Rng.Cells(j, 1).Value Then
Exit For
End If
Next
WorkRng.Parent.Range(Rng.Cells(i, 1), Rng.Cells(j - 1, 1)).Merge
i = j - 1
Next
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
3。 然後按 F5 鍵以運行此代碼,屏幕上會顯示一個對話框,用於選擇要使用的範圍。 看截圖:
4. 然後點擊 OK,則A列中的相同數據將合併在一起。 看截圖:
使用Kutools for Excel合併相同數據的相鄰行
隨著 合併相同的單元格 的效用 Excel的Kutools,您只需單擊一下即可快速合併多個列中的相同值。
Excel的Kutools : 帶有300多個便捷的Excel加載項,可以在30天內免費試用. |
安裝後 Excel的Kutools,您可以執行以下操作:
1。 選擇要合併具有相同數據的相鄰行的列。
2。 點擊 庫工具 > 合併與拆分 > 合併相同的單元格,請參見屏幕截圖:
3。 然後,所選列中的相同數據已合併到一個單元格中。 看截圖:
要了解更多信息,請訪問此 合併相同的單元格 功能。
演示:將相同的單元格合併到一個單元格中,或取消合併以填充重複的值:
Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!
最佳辦公生產力工具
🤖 | 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%,每天為您減少數百次鼠標點擊!
Sort comments by
#44313
This comment was minimized by the moderator on the site
0
0
#40732
This comment was minimized by the moderator on the site
0
0
#40705
This comment was minimized by the moderator on the site
0
0
#40729
This comment was minimized by the moderator on the site
Report
0
0
#34596
This comment was minimized by the moderator on the site
Report
0
0
#34595
This comment was minimized by the moderator on the site
0
0
#33623
This comment was minimized by the moderator on the site
0
0
#31689
This comment was minimized by the moderator on the site
0
0
#29259
This comment was minimized by the moderator on the site
0
0
#29260
This comment was minimized by the moderator on the site
0
0
#27540
This comment was minimized by the moderator on the site
0
0
#27541
This comment was minimized by the moderator on the site
Report
0
0
#26595
This comment was minimized by the moderator on the site
Report
0
0
#26596
This comment was minimized by the moderator on the site
Report
0
0
There are no comments posted here yet