我有一些具有两千行的电子表格。我想要一个宏,该宏将计算“ A”列中单元格中的字符数,如果该行少于8个字符,则将其删除。
答案 0 :(得分:0)
请在Excel上运行此代码
Sub DelRows()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
If Len(Range("A" & i).Value) < 8 Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub
答案 1 :(得分:0)
您可以尝试:
Option Explicit
Sub test()
Dim ws As Worksheet
Dim Lastrow As Long, Row As Long
'Loop sheets
For Each ws In ThisWorkbook.Worksheets
With ws
'Find Last row of column A in sheet ws
Lastrow = .cells(.Rows.Count, "A").End(xlUp).Row
'Loop rows from bottom to top
For Row = Lastrow To 1 Step -1
'Check value lenght
If Len(.Range("A" & Row).Value) > 8 Then
.Rows(Row).Delete
End If
Next Row
End With
Next ws
End Sub