跳到主要內容

如何從Excel中的文本中刪除第一個,最後X個字符或某些位置字符?

對於大多數Excel用戶,有時,您需要從文本字符串的開頭刪除前n個字符,或者從文本字符串的結尾刪除最後x個字符,如下面的屏幕快照所示。 本文,我將介紹一些方便的技巧,以在Excel中快速輕鬆地解決此任務。
 

doc刪除前x個字符1


方法1:使用公式從文本字符串中刪除第一個或最後一個x個字符

 從文本字符串的開頭刪除前x個字符:

在Excel中,可以使用RIGHT和LEFT函數從字符串的開頭或結尾刪除一定數量的字符,請執行以下操作:

1。 在要放入結果的空白單元格C4中鍵入或複制以下公式:

=RIGHT(A4, LEN(A4)-2)

並按下 Enter 獲得第一個結果的關鍵。 看截圖:

doc刪除前x個字符2

備註:在以上公式中:

  • A4 是要刪除字符的單元格值;
  • 數量 2 表示要從文本字符串開頭刪除的字符數。

2。 然後,選擇單元格C4並將填充手柄向下拖動到要應用此公式的單元格,並且所有前兩個字符已從文本字符串中刪除,請參見屏幕截圖:

doc刪除前x個字符3


 從文本字符串的末尾刪除最後x個字符:

如果需要刪除最後幾個字符,則可以將LEFT函數與RIGHT函數相同。

請輸入此公式或將其複製到空白單元格中:

=LEFT(A4, LEN(A4)-9)

然後將填充手柄向下拖動到要應用此公式的單元格上,並且最後一次從文本字符串中刪除了最後9個字符,請參見屏幕截圖:

doc刪除前x個字符4

備註:在以上公式中:

  • A4 是要刪除字符的單元格值;
  • 數量 9 表示要從文本字符串末尾刪除的字符數。

方法2:使用用戶定義的功能從文本字符串中刪除第一個或最後一個x個字符

這是一個用戶定義函數,它也可以幫助您從文本字符串中刪除前n個字符或後n個字符,請執行以下操作:

 從文本字符串的開頭刪除前x個字符:

1。 按住 Alt + F11鍵 鍵打開 Microsoft Visual Basic for Applications 窗口。

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

Public Function removeFirstx(rng As String, cnt As Long)
removeFirstx = Right(rng, Len(rng) - cnt)
End Function

3。 然後回到工作表,然後輸入以下公式: =removefirstx(A4,2) 放入空白單元格,然後向下拖動填充手柄以獲取所需的結果,請參見屏幕截圖:

doc刪除前x個字符5

備註:在以上公式中:

  • A4 是要刪除字符的單元格;
  • 數量 2 表示您要從文本字符串開頭刪除的字符數。

 從文本字符串的末尾刪除最後x個字符:

要從文本字符串中刪除最後n個字符,請應用以下用戶定義函數:

Public Function removeLastx(rng As String, cnt As Long)
removeLastx = Left(rng, Len(rng) - cnt)
End Function

然後應用以下公式: =removelastx(A4,9) 要獲得所需的結果,請參見屏幕截圖:

doc刪除前x個字符6

備註:在以上公式中:

  • A4 是要刪除字符的單元格;
  • 數量 9 表示要從文本字符串末尾刪除的字符數。

方法3:刪除沒有任何公式的第一個,最後一個x個字符或某些位置字符

使用Excel函數刪除某些字符並非如此。 只需看一下此方法提供的方式即可,只需單擊兩三個鼠標即可。 隨著 按位置刪除 第三方加載項的實用程序 Excel的Kutools,您可以輕鬆地從文本字符串中刪除開頭,結尾或某些字符。 點擊下載Kutools for Excel! 請參見下面的演示:

安裝後 Excel的Kutools,請申請 按位置刪除 根據以下步驟:

1。 選擇要刪除某些字符的範圍。 然後點擊 庫工具 > 文本 > 按位置刪除。 看截圖:

2。 在彈出窗口中指定以下操作 按位置刪除 對話框。

  • (1.)指定要刪除的字符數。
  • (2.)選擇 從左起 選項下 位置 部分刪除前n個字符,請參見屏幕截圖:

doc刪除前x個字符8

提示:  按位置刪除 實用程序還可以幫助您從特定位置刪除最後n個字符或某些字符。

方法4:使用公式從文本字符串中刪除前x個字符和後x個字符

有時,您想從兩側的文本字符串中刪除字符,例如,您需要同時刪除前2個字符和後9個字符。 在此,MID功能可以幫您一個忙。

1。 請輸入此公式或將其複製到空白單元格中:

=MID(A4,3,LEN(A4)-11)

並按下 Enter 獲得第一個結果的關鍵。 看截圖:

doc刪除前x個字符11

備註:在以上公式中:

  • A4 是要刪除字符的單元格值;
  • 數量 3 比您要從左側刪除的字符數多一;
  • 數量 11 是您要刪除的字符總數。

2。 然後,選擇單元格C4並將填充手柄向下拖動到要應用此公式的單元格上,所有前2個字符和後9個字符都已立即從文本字符串中刪除,請參見屏幕截圖:

doc刪除前x個字符12


最佳辦公生產力工具

🤖 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 (134)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I have a problem. I need to remove specific last character in the sheet. Example: I have people names and I need to remove the last character, if it is "a", but that the rest of the name contains the letter "a". How I can do that?
This comment was minimized by the moderator on the site
i want remove the last part ex: (jaison kkrrt po kizha) like an adress want edit only jaison
is it possibile?
This comment was minimized by the moderator on the site
In the nursery (plant) industry, we have a lot of plants that are crosses and have an x after the Genus (1st word). Is there a way to NOT have the x alphabetized? A couple example names: Buxus x 'Green Mountain' and Thuja x 'Green Giant'. These names are constantly at the end of the listing of Buxus and Thuja instead of being near the top. By the way, it's always "space x space". Can there be a way to highlight a column and tell it to ignore the x if proceeded and followed by a space when alphabetizing the names in that column? Thank you.
This comment was minimized by the moderator on the site
Wow! Kutools berfungsi dengan sempurna di Ms. Office Pro Plus 2016. Sungguh menolong saya, menghemat waktu dalam menghapus karakter tertentu di data excel saya. Terima kasih banyak.
This comment was minimized by the moderator on the site
How can I get rid of the last value in a cell IF it is the letter 'N'? Not all have the 'N' at the end and I want to only remove those that do?
This comment was minimized by the moderator on the site
How can I get this number reduced using formulas to make 3604000000157477 to be 3604157477 first 4 to the front and last 6 digits.
This comment was minimized by the moderator on the site
Tengo una ruta en una columna ejm C:\Users\jaja\Downloads\aa.txt. Necesito eliminar todos los carácteres que están después del último slash
This comment was minimized by the moderator on the site
Hi I have a data with names and surnames of some people, i want to separate surname in coloumn and name in another coloumn, surnames are not same like michel, john, daniel, williams like please help me to separate surname by using formula, I have lot of data
This comment was minimized by the moderator on the site
Hi, Giridhar,
Maybe the below article can solve your problem, please try, thank you!
https://www.extendoffice.com/documents/excel/829-excel-split-first-last-name.html
This comment was minimized by the moderator on the site
If number or character differ you can use example below (I needed to remove the last character):
=PART(A1;1;(LENGTH(A1)-1))
This comment was minimized by the moderator on the site
I WANT TO TRIM TEXT LENGTH, FOR EXAMPLE I HAVE SOME ADDRESS THAT LENGTH SOME COLUM 10 CHARECTOR AND SOME COLUM 20 CHARECTOR SOME 15 CHARECTOR IN THIS CASE I WANT TO TRIM WHICH COLUM TEXT MORE THAN 15 I WANT TO TRIM THAT COLUM TEXT TO 15 CHARECTOR, DONT TRIM OTHER COLUM TEXTS


ANYBODY HELP ME
This comment was minimized by the moderator on the site
Use "text to column"
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