跳到主要内容

如何从Excel中的文本中删除第一个,最后X个字符或某些位置字符?

对于大多数Excel用户,有时,您需要从文本字符串的开头删除前n个字符,或者从文本字符串的结尾删除最后x个字符,如下面的屏幕快照所示。 本文,我将介绍一些方便的技巧,以在Excel中快速轻松地解决此任务。
 

doc删除前x个字符1


方法1:使用公式从文本字符串中删除第一个或最后一个x个字符

 从文本字符串的开头删除前x个字符:

在Excel中,可以使用RIGHT和LEFT函数从字符串的开头或结尾删除一定数量的字符,请执行以下操作:

1。 在要放入结果的空白单元格C4中键入或复制以下公式:

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

并按下 输入 获得第一个结果的关键。 看截图:

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应用程序 窗口。

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函数删除某些字符并非如此。 只需看一下此方法提供的方式即可,只需单击两三个鼠标即可。 随着 按位置删除 第三方加载项的实用程序 Kutools for Excel,您可以轻松地从文本字符串中删除开头,结尾或某些字符。 点击下载Kutools for Excel! 请参见下面的演示:

安装后 Kutools for Excel,请申请 按位置删除 根据以下步骤:

1。 选择要删除某些字符的范围。 然后点击 库工具 > 文本 > 按位置删除。 看截图:

2。 在弹出窗口中指定以下操作 按位置删除 对话框。

  • (1.)指定要删除的字符数。
  • (2.)选择 从左边 选项下 职务 部分删除前n个字符,请参见屏幕截图:

doc删除前x个字符8

提示:  按位置删除 实用程序还可以帮助您从特定位置删除最后n个字符或某些字符。

方法4:使用公式从文本字符串中删除前x个字符和后x个字符

有时,您想从两侧的文本字符串中删除字符,例如,您需要同时删除前2个字符和后9个字符。 在这里,MID功能可以帮您一个忙。

1。 请输入此公式或将其复制到空白单元格中:

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

并按下 输入 获得第一个结果的关键。 看截图:

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 Tab 为 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