You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在MS Excel中筛选列内包含或仅含英文字母的单元格?

Excel混合内容列英文字母筛选方案

前置准备:添加自定义VBA函数

Excel自带筛选工具无法直接识别字符编码范围,我们通过自定义VBA函数实现需求,操作步骤如下:

  1. 按Alt+F11打开VBA编辑器,右键点击当前工作簿名称→「插入」→「模块」
  2. 将以下代码粘贴到模块编辑区:
' 检查单元格是否包含任意英文字母(含带音调的拉丁字母)
Function HasEnglish(rng As Range) As Boolean
    Dim i As Long, charCode As Long
    For i = 1 To Len(rng.Value)
        charCode = AscW(Mid(rng.Value, i, 1))
        ' 匹配基础拉丁字母、补充拉丁字母,排除乘号除号符号
        If (charCode >= 65 And charCode <= 90) Or _
           (charCode >= 97 And charCode <= 122) Or _
           (charCode >= 192 And charCode <= 255 And charCode <> 215 And charCode <> 247) Then
            HasEnglish = True
            Exit Function
        End If
    Next i
    HasEnglish = False
End Function

' 检查单元格是否仅包含英文字母,支持自定义是否允许空格、英文标点
Function OnlyEnglish(rng As Range, Optional AllowSpace As Boolean = False, Optional AllowPunctuation As Boolean = False) As Boolean
    Dim i As Long, charCode As Long
    If Len(rng.Value) = 0 Then
        OnlyEnglish = False
        Exit Function
    End If
    For i = 1 To Len(rng.Value)
        charCode = AscW(Mid(rng.Value, i, 1))
        ' 匹配英文字母
        If (charCode >= 65 And charCode <= 90) Or _
           (charCode >= 97 And charCode <= 122) Or _
           (charCode >= 192 And charCode <= 255 And charCode <> 215 And charCode <> 247) Then
            GoTo NextChar
        End If
        ' 匹配允许的空格
        If AllowSpace And charCode = 32 Then
            GoTo NextChar
        End If
        ' 匹配允许的英文标点
        If AllowPunctuation Then
            If (charCode >= 33 And charCode <= 47) Or (charCode >= 58 And charCode <= 64) Or _
               (charCode >= 91 And charCode <= 96) Or (charCode >= 123 And charCode <= 126) Then
                GoTo NextChar
            End If
        End If
        ' 出现非允许字符直接返回否
        OnlyEnglish = False
        Exit Function
NextChar:
    Next i
    OnlyEnglish = True
End Function
  1. 关闭VBA编辑器即可调用函数

需求1:筛选包含任意英文字母的单元格

  • 在待筛选列旁插入空白辅助列,数据首行对应单元格输入公式=HasEnglish(A1),将A1替换为待筛选列的首个数据单元格
  • 下拉填充公式到所有数据行,返回值为TRUE的就是包含英文字母的单元格,你举例的混合语言单元格会正确返回TRUE
  • 点击「数据」选项卡→「筛选」,筛选辅助列值为TRUE的行即可

需求2:筛选仅包含英文字母的单元格

  • 同样插入空白辅助列,根据你的规则选择对应公式输入到数据首行:
    • 仅允许纯英文字母(无空格、无标点):=OnlyEnglish(A1)
    • 允许英文内容之间带空格:=OnlyEnglish(A1,TRUE)
    • 允许空格+常见英文标点:=OnlyEnglish(A1,TRUE,TRUE)
  • 下拉填充公式后,筛选辅助列值为TRUE的行即可

保存文件时需要选择「Excel 启用宏的工作簿(*.xlsm)」格式,否则自定义函数会失效
如果不需要识别带音调的拉丁字母,删除代码中(charCode >= 192 And charCode <= 255 And charCode <> 215 And charCode <> 247)相关判断段即可

内容的提问来源于stack exchange,提问作者Akbarali Charankav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 02:45:02