复制列中重复次数少于100次的数据-Excel-VBA

时间:2018-08-07 04:25:49

标签: excel vba

具有非常庞大的Excel数据。我想将数据从C列复制到有条件的其他工作表中。具有n个文本值的C列只希望重复包含少于100次的单词。

Sub DelR() 

    Dim myRow As Range 
    Dim to Delete As Range 
    For I=2 to 10000 
    If workseets("Sheet1").Cells(I,2) >100 Then 
    Set myRow = Worksheets("Sheet1").Rows(I) 
    If toDelete = myRow Else 
    Set to Delete = Union(toDelete, myRow) 
    End If 
    End If 
    Next I 
    If Not toDelete Is Nothing Then toDelete.EntireRow.Delete 

End Sub

1 个答案:

答案 0 :(得分:1)

Sub DelR() 
    Dim sht As WorkSheet
    Dim myRow As Range 
    Dim to Delete As Range 
    Set sht = worksheets("Sheet1")
    For I=2 to 10000 
        If Application.Countif(sht.Columns(2), _
                               sht.Cells(I,2).Value) >100 Then 
            Set myRow = sht.Rows(I) 
            If toDelete Is Nothing 
                Set toDelete = myRow
            Else 
                Set toDelete = Application.Union(toDelete, myRow) 
            End If 
        End If 
    Next I 
    If Not toDelete Is Nothing Then toDelete.EntireRow.Delete 

End Sub