跳到主要內容

如何從Excel中的單元格或字符串中刪除前n個或後n個字符?

本教程演示了從Excel中的單元格或字符串中刪除前N個字符或後N個字符的各種快速技巧。

doc先刪除後1 1.使用公式/ UDF刪除前N個字符
2.使用公式/ UDF刪除最後N個字符
3.從左,右或中間不帶公式的批處理中刪除N個字符
4.下載樣本文件

1.用公式刪除前N個字符

在這一部分中,我介紹了三種快速從字符串中刪除前N個字符的方法。

1.1使用RIGHT / REPLACE功能刪除前N個字符

>> 結合使用RIGHT和LEN功能刪除前N個字符

公式語法和參數

公式:= RIGHT(string_cell,LEN(string_cell)-n_character)

參考:string_cell:用於刪除字符的單元格

n_character:要刪除的字符數

示例:從單元格A2中的字符串中刪除前2個字符,然後復制並粘貼公式
=右(A2,LEN(A2)-2)
Enter 關鍵
doc先刪除後2

>> 替換功能刪除前N個字符

公式語法和參數

公式:= REPLACE(Old_text,Strat_n,Num_Chars,New_text)

參考:Old_text:用於替換字符的單元格

Old_text:用於替換字符的單元格

Start_n:要用new_text替換的字符在old_text中的位置

Num_Chars:要用new_text替換的舊文本中的字符數

New_text:將替換old_text的文本

示例:在單元格A6中將前兩個字符替換為空,然後復制並粘貼此公式:
= REPLACE(A6,1,2,“”)
Enter 關鍵
doc先刪除後3

1.2使用用戶定義的功能刪除前N個字符

1。 按 Alt + F11鍵 鍵以啟用“ Microsoft Visual Basic for Applications”窗口,然後單擊“確定”。 插入 > 模塊 創建一個模塊。

2.複製以下代碼並將其粘貼到 模塊 腳本。

VBA代碼:刪除前n個字符

Public Function RemoveFirstC(rng As String, cnt As Long)

RemoveFirstC = Right(rng, Len(rng) - cnt)

End Function

3.保存代碼,然後返回使用的工作表。 例如,從單元格A3中的字符串中刪除前11個字符,然後復制並粘貼此公式
= RemoveFirstC(A11,3)
Enter 關鍵
doc先刪除後4


刪除職位

此刪除字符工具可將您的效率提高90%,並留出大量時間來享受生活

▲告別修改和記憶公式,讓您充分休息。

▲除此工具外,還有228種高級工具 (包括30多種文本編輯工具) 其他在 Kutools for Excel 中,它可以解決你的問題 企業排放佔全球 80% Excel 拼圖。

▲在5分鐘內成為Excel專家,獲得人們的認可和提升。

▲110000多名高效率人才和300多家世界知名企業的選擇。

30天免費試用,無需信用卡


2.使用公式刪除最後N個字符

在這一部分中,有兩種​​方法可以從Excel中的字符串中刪除最後N個字符。

2.1使用LEFT功能刪除最後N個字符

公式語法和參數

公式:= LEFT(string_cell,LEN(string_cell)-Num_chars)

參考:string_cell:用於刪除字符的單元格

n_character:要刪除的字符數

示例:從單元格A2中的字符串中刪除最後2個字符,然後復制並粘貼公式
=左(A2,LEN(A2)-2)
Enter 關鍵
doc先刪除後5

2.2使用用戶定義的功能刪除最後N個字符

1。 按 Alt + F11鍵 鍵以啟用“ Microsoft Visual Basic for Applications”窗口,單擊 插入 > 模塊 創建一個模塊。

2.複製以下代碼並將其粘貼到模塊腳本中。

VBA代碼:刪除最後n個字符

Public Function RemoveLastC(rng As String, cnt As Long)

RemoveLastC = Left(rng, Len(rng) - cnt)

End Function

3.保存代碼,然後返回使用的工作表。 例如對於從單元格A3中的字符串中刪除最後5個字符,鍵入此公式
= RemoveLastC(A5,3)
Enter 關鍵
doc先刪除後6


其他

您想加薪並有很多時間陪伴家人嗎?

Office選項卡可將Microsoft Office立即工作的效率提高50%

令人難以置信的是,處理兩個或多個文檔比處理一個或多個文檔更容易,更快捷。

與知名瀏覽器相比,Office Tab中的選項卡式工具功能更強大,更高效。

每天為您減少數百次鼠標單擊和鍵盤輸入,現在告別鼠標手。

如果您通常處理多個文檔,Office Tab將為您節省大量時間。

30-天免費試用,無需信用卡。

閱讀更多現在免費下載


3.從左,右或中間刪除無公式的N個字符

如果您不想浪費時間記住處理從字符串的左側或右側刪除N個字符的任務的公式,則 按位置刪除 的效用 Excel的Kutools 無需任何公式,點擊即可完成此任務。

現在,讓您比其他人更快更好地工作,輕鬆獲得晉升

35個用於Excel的文本編輯工具可將您的文本處理效率提高90%,並留出大量時間享受生活

這些工具只是 Kutools for Excel 的一部分,還有 194 其他工具可以解決 企業排放佔全球 80% Excel 難題為您服務。

  • Kutools for Excel 幫助您輕鬆應付1500種工作場景,平均每天提高71%的效率
  • 一鍵式完成大多數複雜的操作,為您避免由數千次鼠標單擊引起的鼠標手。
  • 您可以在幾秒鐘內處理Excel任務,而無需搜索痛苦的公式和VBA,並且有更多的時間陪伴家人。
  • 被超過110000多名高效人員和超過{module708}世界知名企業選擇。

免費安裝Kutools for Excel後,請執行以下操作:

選擇您要從中刪除字符的單元格,通過單擊來應用該實用程序 庫工具 > 文本 > 按位置刪除.
doc先刪除後7

3.1刪除不帶公式的前/後N個字符

>> 刪除前N個字符

doc先刪除後8

1)在 民數記 在文本框中,輸入要從字符串中刪除的字符數,在此示例中,我將首先刪除 3 字符串中的字符。

2)檢查 從左起 選項 位置 部分。

結果顯示為:
doc先刪除後9

>> 刪除最後N個字符

doc先刪除後10

1)在 民數記 在文本框中,輸入您要從字符串中刪除的字符數,在此示例中,我將刪除最後一個 3 字符串中的字符。

2)檢查 從右邊 選項 位置 部分。

結果顯示為:
doc先刪除後11

3.2從中間特定位置刪除N個字符而無需公式

但是有時候,您可能希望從字符串中間刪除特定數量的字符。

示例:從字符串的第三個字符開始刪除3個字符。

doc先刪除後12

1)在 聯繫電話 文本中,輸入您要從字符串中刪除的字符數,在此我將刪除 3 字符。

2)檢查 指定 選項,然後在其中的文本框旁邊輸入要刪除字符串開頭的數字 位置 部分,在這裡我將從第三個字符中刪除字符。

結果顯示為:
doc先刪除後13

按位置刪除字符,無需公式

按位置刪除

小提示: 如果要從單元格中刪除所有數字,字母,非數字,非字母或特定字符,則可以將Kutools for Excel的 刪除字符 效用。
按字符刪除

有關刪除字符的更多提示...


下載樣本文件

樣品


推薦的生產力工具

Office選項卡-Microsoft Office 2019-2003和Office 365中的選項卡式瀏覽,編輯,文檔管理


辦公室標籤

Kutools for Excel - 收集超過 300 個進階工具,可在日常 Excel 工作中節省 50% 的時間


kutools選項卡
kutoolsp選項卡
Comments (19)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Helpful Article
This comment was minimized by the moderator on the site
buenísimo, mil gracias!!
This comment was minimized by the moderator on the site
Gracias por tu ayuda me sirvió mucho, utilizando en vez de izquierda, DERECHA se obtienen tambien buenos resultados...Gracias. 
This comment was minimized by the moderator on the site
Merci vraiment ca m'a beaucoup aidé, thanks it is very useful
This comment was minimized by the moderator on the site
Love this!!! Explained clearly. Easy to follow. Worked!!! Thanks!
This comment was minimized by the moderator on the site
Thanks, great help.
This comment was minimized by the moderator on the site
"658414 Mottagares kundnummer Menigo Rutt VÄX319" is my information, but I'm only interested in the last six letters/numbers. Any ideas?
This comment was minimized by the moderator on the site
Hi, Krets, you can use this formula =RIGHT(A1, 6) to extract last 6 characters in another cell. For more details, please read this article:

https://www.extendoffice.com/documents/excel/1656-excel-extract-first-character.html
This comment was minimized by the moderator on the site
"A/P MALKAWATHE,,TALUKA SOUTH SOLAPUR,SOLAPUR,Solapur,413252" this is my data. I want pincode separated from the data. by using =RIGHT(P2,LEN(P2)-6) it is not working.
This comment was minimized by the moderator on the site
You want to extract last 6 characters, the formula =RIGHT(P2,6) may help you, more details, please go to this article.https://www.extendoffice.com/documents/excel/3639-excel-extract-part-of-string.html
This comment was minimized by the moderator on the site
nice its work nice thank you very much
This comment was minimized by the moderator on the site
Just what I needed!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations