跳到主要內容

如何快速從Excel中的單元格中刪除破折號?

假設在工作表單元格中有一個郵政編碼列表或較長的ISBN數字,並且較長的數字包含破折號,出於某種目的,您需要消除數字之間的破折號(如以下屏幕截圖所示)。 有什麼快速方法可以刪除excel中數字之間的這些破折號?

用公式從單元格中刪除破折號
使用VBA代碼從單元格中刪除破折號
使用Kutools for Excel輕鬆刪除單元格中的破折號


用公式從單元格中刪除破折號

有了這個 替代 函數,數字將轉換為文本值,因此,當您刪除破折號時,前導0不會被刪除,數字也不會成為科學計數法。 請執行以下操作:

1。 在相鄰的空白單元格(例如C1)中,輸入以下公式: = SUBSTITUTE(A1,“-”,“”),請參見屏幕截圖:

2。 按 Enter 鍵,然後選擇單元格C1,然後將填充手柄拖到要包含此公式的範圍。 數字之間的破折號已被刪除。 看截圖:

從Excel的單元格中輕鬆刪除所有數字,非數字或指定字符,例如“破折號”:

Excel的Kutools's 刪除字符 實用程序可幫助您輕鬆刪除Excel中選定單元格中的所有數字,非數字或指定字符。
立即下載並試用! (30 天免費試用)


使用VBA代碼從單元格中刪除破折號

使用以下VBA代碼,您還可以從一系列單元格中刪除數字之間的破折號。

1。 突出顯示您要刪除破折號的範圍。

2。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

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

VBA:刪除數字之間的破折號

Sub DeleteDashes()
'Update 20130907
Dim rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For Each rng In WorkRng
    rng.NumberFormat = "@"
    rng.Value = VBA.Replace(rng.Value, "-", "")
Next
Application.ScreenUpdating = True
End Sub

4。 然後按 F5 鍵以運行此代碼,然後會彈出一個對話框,提示您選擇要使用的範圍。 看截圖:

5。 然後點擊 OK,數字之間的破折號已從單元格中刪除。 並將數字格式轉換為文本格式。 查看屏幕截圖:


使用Kutools for Excel從單元格中刪除破折號

如果您是Excel的初學者,那麼公式和代碼對您來說都很難,請不要擔心, Excel的Kutools刪除字符 功能可以幫助您快速刪除單元格中的破折號。

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

1。 選擇您需要刪除破折號的單元格的範圍,然後單擊 庫工具 > 文本 > 刪除字符,請參見屏幕截圖:

2。 在 刪除字符 對話框,檢查 習俗 選項,然後輸入“-“字符”輸入文本框,然後您可以從 預覽 窗格。 然後點擊 OK 按鈕可刪除所選單元格中的所有破折號。 看截圖:

備註。 如果選定的單元格包含前導零或很多數字,為保持前導零並避免數字在刪除破折號後成為科學計數法,則需要將單元格格式設置為“文本”,如下圖所示,然後應用 刪除字符 效用。

  如果您想免費試用(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 (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
this and the concatenate command have saved my brain from melting! thank you!
This comment was minimized by the moderator on the site
Sub DeleteDashes() 'Update 20130907 Dim rng As Range Dim WorkRng As Range On Error Resume Next xTitleId = "KutoolsforExcel" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) Application.ScreenUpdating = False For Each rng In WorkRng rng.NumberFormat = "@" rng.Value = VBA.Replace(rng.Value, "-", "") Next Application.ScreenUpdating = True End Sub
This comment was minimized by the moderator on the site
unimpressed with your instructions - using the =SUBSTITUTE formula above, the leading zeros are stripped
This comment was minimized by the moderator on the site
THANK YOU EXTEND OFFICE IT'S VERY HELPFUL AND SIMPLE.. KUDOS!
This comment was minimized by the moderator on the site
Use the find and replace feature. (Ctrl + F, click the replace tab). Enter "-" Into the find field (or whatever you're trying to remove) and hit the replace button. Make sure you leave the "Replace with" field blank.
This comment was minimized by the moderator on the site
Great it works
This comment was minimized by the moderator on the site
WOW.... You win this whole thread, THANK YOU!!!
This comment was minimized by the moderator on the site
Hi, This is manish gupta and it is the good code of removing the border areas in excel sheets. thanks and regards manish gupta
This comment was minimized by the moderator on the site
HI , MY PROBMEL SOLVE PLEASE
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations