如果单元格值包含字母和数字,请删除行

时间:2016-10-20 11:48:08

标签: excel vba excel-vba

请告诉我什么是过滤器来检查单元格是否包含字母和数字,或者单元格是否只包含字母?如果仅包含数字,则必须传递给下一个单元格。我一直在搜索,但唯一的结果是如果单元格包含某些值或文本但我无法找到一个示例形式我的问题。

    With ActiveSheet
    Firstrow = .UsedRange.Cells(1).Row
    Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
    For Lrow = Lastrow To Firstrow Step -1
        With .Cells(Lrow, "e")
          If .Value = " cell has letters AND numbers OR just letters " Then
            .EntireRow.Delete  
          End With
        Next Lrow
    End With

3 个答案:

答案 0 :(得分:2)

在:

enter image description here

我会检查每个角色:

Sub qwerty()
    Dim KillMe As Boolean, CH As String
    With ActiveSheet
        Firstrow = .UsedRange.Cells(1).Row
        Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
        For Lrow = Lastrow To Firstrow Step -1
            KillMe = False
            With .Cells(Lrow, "e")
                For i = 1 To Len(.Value)
                    CH = Mid(.Value, i, 1)
                    If CH Like "[a-zA-Z]" Then KillMe = True
                Next i
                If KillMe Then .EntireRow.Delete
            End With
        Next Lrow
    End With
End Sub

注意:

这会忽略标点符号和特殊字符。它仅查找字母。

之后:

enter image description here

答案 1 :(得分:1)

使用像这样的WorksheetFunction:

Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
...
If Application.Evaluate("=Count(Find({0,1,2,3,4,5,6,7,8,9}," & _ 
.Address & ")) > 0") Then    
...

答案 2 :(得分:0)

根据您可以使用的单元格格式

With ActiveSheet Firstrow = .UsedRange.Cells(1).Row Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row For Lrow = Lastrow To Firstrow Step -1 With .Cells(Lrow, "e") If worksheetfunction.IsText(.Value) Then .EntireRow.Delete
End With Next Lrow End With