跳到主要内容

如何从Excel中的字符串中删除一些特殊字符?

如果有一些特殊字符,例如 %^&*() 现在,您要从单元格字符串中删除这些特定字符。 逐一删除它们很费时,在这里,我将介绍一些快速技巧来解决Excel中的这一任务。

使用用户定义函数从文本字符串中删除一些特殊字符

使用 Kutools for Excel 从文本字符串中删除一些特殊字符


箭头蓝色右气泡 使用用户定义函数从文本字符串中删除一些特殊字符

以下VBA代码可以帮助您删除所需的特定字符,请执行以下操作:

1. 按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到 模块 窗口。

VBA代码:从文本字符串中删除一些特殊字符

Function RemoveSpecial(Str As String) As String
'updatebyExtendoffice 20160303
    Dim xChars As String
    Dim I As Long
    xChars = "#$%()^*&"
    For I = 1 To Len(xChars)
        Str = Replace$(Str, Mid$(xChars, I, 1), "")
    Next
    RemoveSpecial = Str
End Function

3。 然后保存并关闭此代码,返回到工作表,然后输入以下公式: = removespecial(A2) 放入要放入结果的空白单元格,请参见屏幕截图:

doc删除特殊字符1

4。 然后将填充手柄向下拖动到要应用此公式的单元格上,所有不需要的特殊字符都已从文本字符串中删除,请参见屏幕截图:

doc删除特殊字符2

备注:在上面的代码中,您可以更改特殊字符 #$%()^ *& 您想要删除的其他任何人。


从文本字符串中去除数字,字母或其他特殊字符

Kutools for Excel's 删除字符 功能可以帮助您快速删除所有 数字, 阿尔法, 非数字, 非字母, 非印刷, 其他特定字符 从文本字符串根据需要。 单击立即下载并免费试用 Kutools for Excel!

doc删除特殊字符7

Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!


如果您不熟悉VBA代码, Kutools for Excel删除字符 实用程序可以帮助您快速轻松地完成此任务。

安装后 Kutools for Excel,请这样:

1。 选择要删除某些特殊字符的文本字符串。

2. 点击 库工具 > 文本 > 删除字符,请参见屏幕截图:

3。 在 删除字符 对话框,检查 定制版 选项下 删除字符 部分,然后输入要删除的特殊字符,请参见屏幕截图:

doc删除特殊字符4

4。 然后点击 Ok or 使用 按钮,您在 定制版 文本框已立即从文本字符串中删除,请参见屏幕截图:

doc删除特殊字符5 2 doc删除特殊字符6

单击立即下载并免费试用 Kutools for Excel!


Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!

最佳办公生产力工具

🤖 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 (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Excelllent .. Five Stars.. thanks a lot
This comment was minimized by the moderator on the site
Thanks for this code
Function RemoveSpecial(Str As String) As String
'updatebyExtendoffice 20160303
Dim xChars As String
Dim I As Long
xChars = "#$%()^*&"
For I = 1 To Len(xChars)
Str = Replace$(Str, Mid$(xChars, I, 1), "")
Next
RemoveSpecial = Str
End Function

But it is possible that that can remove specific text? like "ab", "abc", "bc" and etc.
This comment was minimized by the moderator on the site
With Emoji need remove, how ?
This comment was minimized by the moderator on the site
Rather than searching for specific special characters, how about if you want to search for and replace ALL special characters. In other words, how would you write the search for NOT one of the following characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
This comment was minimized by the moderator on the site
Hi, Nick,
Do you want to remove all ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 characters from the cells?
Looking forward to your reply, thank you!
This comment was minimized by the moderator on the site
No. I want to keep only "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
This comment was minimized by the moderator on the site
Nick,
Maybe the below VBA code can solve your problem, please try:

Sub RemoveNotAlphasNotNum()
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)
For Each Rng In WorkRng
xOut = ""
For i = 1 To Len(Rng.Value)
xTemp = Mid(Rng.Value, i, 1)
If xTemp Like "[a-z.]" Or xTemp Like "[A-Z.]" Or xTemp Like "[0-9.]" Then
xStr = xTemp
Else
xStr = ""
End If
xOut = xOut & xStr
Next i
Rng.Value = xOut
Next
End Sub


Hope it can help you!
This comment was minimized by the moderator on the site
Hmm I wonder, does it only work in the worksheet you've originally pasted the code in?
As for that one it only seems to work, not for any new workbook you open
This comment was minimized by the moderator on the site
Hello, Kim,
The VBA code can only applied in one workbook, if you want to apply it in a new workbook, you should copy and paste the code into your new workbook again.
Thank you!
This comment was minimized by the moderator on the site
Hi guys,

I've applied the =removespecial(A2) code and it works perfectly in one worksheet but then in the other it gives me an invalid #NAME? error.
I checked the "format cells" and it's both on general and I've copied the same text + formula to both worksheets but it won't work.
Any clue what this might cause this?

Thanks and thank you so much for this code.
Saves me hours and hours of work!

Regards, Kim
This comment was minimized by the moderator on the site
Function GetWordWOSpecChar(Rng As Range)
'paste in VBA module, Use as a Formula
'Created by Deepak Sharma
Arr = Array("48", "49", "50", "51", "52", "53", "54", "55", _
"56", "57", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", _
"76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", _
"89", "90", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", _
"107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", _
"118", "119", "120", "121", "122")

For i = 1 To Len(Rng.Value)
txt = Mid(Rng.Value, i, 1)
For g = 1 To UBound(Arr)
If txt = Chr(Arr(g)) Then GetWord = Right(Rng.Value, Len(Rng.Value) - (i - 1)): Exit Function
Next g
Next i

End Function
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations