如果不是 A-Z,则删除所有单元格

Delete All Cells if not A-Z

我正在处理 6 列数据 (A-F) 第 2-4379 行,大量单元格在过滤器列中显示为 "Blanks" 但不是 true 空白,因为它们似乎包含空格。我希望找到一些 vba 示例来查找包含 65-90 和 97-122 之间的 ASCII 值的范围内的所有单元格,如果这些值不包含在单元格中,则完全清除它。

这可能吗?我尝试了一个检查 "IsText" 的子程序,但一直收到与 IsText 行相关的 "sub or function not defined" 错误消息。

这是我目前尝试过的方法:

Dim c As Range
Dim rng As Range

Set rng = Range("A2:F4379")

For Each c in rng

If Not IsText(c.Value) Then
c.ClearContents
End If

Next c

这应该从活动中删除大部分空格 sheet:

Option Explicit

Public Sub trimWhiteSpaces()

    With ActiveSheet.UsedRange

        .Replace What:=" ", Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:="  ", Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:="   ", Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:="    ", Replacement:=vbNullString, LookAt:=xlWhole

        .Replace What:=vbTab, Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:=vbCrLf, Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:=vbCr, Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:=vbLf, Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:=vbNewLine, Replacement:=vbNullString, LookAt:=xlWhole

        .Replace What:=vbNullChar, Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:=vbBack, Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:=vbFormFeed, Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:=vbVerticalTab, Replacement:=vbNullString, LookAt:=xlWhole
        .Replace What:=vbObjectError, Replacement:=vbNullString, LookAt:=xlWhole

    End With

End Sub

.

注意事项:

您的初始代码有错误,因为您没有将它包含在 Sub() 中

您可以使用类似这样的结构修复它:

Option Explicit

Public Sub testSub()
    Dim c As Range
    Dim rng As Range

    Set rng = Range("A2:F4379")

    For Each c In rng
        If Not IsText(c.Value) Then
            c.ClearContents
        End If
    Next
End Sub