感谢您对以下查询的帮助!
我希望创建一个宏,如果A列的单元格中的值不是以数字开头,那么它将帮助我删除整行。
例如,如果A列中的值如下:-
Column A
12345 Good
A1234 Delete
D5640 Delete
54689 Good
问候 西米
答案 0 :(得分:0)
您可以测试第一个字符Isnumeric
。使用Union
收集不以数字开头的行,并一次性删除所有行。
Option Explicit
Public Sub DeleteRows()
Dim rng As Range, unionRng As Range
Application.ScreenUpdating = False
With Worksheets("Sheet1")
For Each rng In .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row) 'Or A2 to skip headers
If Not IsNumeric(Left$(rng.Value, 1)) Then
If Not unionRng Is Nothing Then
Set unionRng = Union(unionRng, rng)
Else
Set unionRng = rng
End If
End If
Next
End With
If Not unionRng Is Nothing Then unionRng.EntireRow.Delete
Application.ScreenUpdating = True
End Sub