简体   繁体   English

删除长度小于8个字符的单元格

[英]Remove cell with a length, lower than 8 characters

I have some spreadsheets with a couple thousand rows. 我有一些具有两千行的电子表格。 I'd like a macro that will count the number of characters in the cells in the 'A' column and delete the row if it's less than 8 characters. 我想要一个宏来计算'A'列中单元格中的字符数,如果它少于8个字符,则删除该行。

please run this code on Excel 请在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

You could try: 你可以尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM