提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

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

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

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

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


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

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

doc删除特殊字符7

Kutools for Excel:比200方便的Excel加载项,可以在60天免费试用。 下载并免费试用现在!


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


以下VBA代码可以帮助您删除所需的特定字符,请按照以下步骤操作:

1. 按住 ALT + F11 键打开 Microsoft Visual Basic for Applications 窗口。

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

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


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

Kutools for Excel : 与超过300方便的Excel加载项,在60天免费试用没有限制.

安装后 Kutools for Excel请如下所示:

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

2. 点击 Kutools > 文本 > 删除字符,看截图:

doc删除特殊字符3

3。 在 删除字符 对话框,检查 私人订制 选项下 删除字符 部分,然后输入要移除的特殊字符,请参阅截图:

doc删除特殊字符4

4。 然后点击 Ok or 申请 按钮,您在中指定的字符 私人订制 文本框一次从文本字符串中删除,请参阅屏幕截图:

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

点击下载并免费试用Kutools for Excel Now!


Kutools for Excel:比200方便的Excel加载项,可以在60天免费试用。 下载并免费试用现在!


Kutools for Excel解决了您的大多数问题,并使您的生产率提高了80%

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能30天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Nick DeCastro · 2 months ago
    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"
    • To post as a guest, your comment is unpublished.
      skyyang · 2 months ago
      Hi, Nick,
      Do you want to remove all ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 characters from the cells?
      Looking forward to your reply, thank you!
      • To post as a guest, your comment is unpublished.
        Nick DeCastro · 2 months ago
        No. I want to keep only "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
        • To post as a guest, your comment is unpublished.
          skyyang · 2 months ago
          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!
  • To post as a guest, your comment is unpublished.
    Kim · 8 months ago
    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
    • To post as a guest, your comment is unpublished.
      skyyang · 8 months ago
      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!
  • To post as a guest, your comment is unpublished.
    Kim · 8 months ago
    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
  • To post as a guest, your comment is unpublished.
    Deepak · 1 years ago
    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