简体   繁体   中英

Based on a Filtered count value from one sheet, need to insert empty rows in another sheet

i have certain cell values of range (A1:A10) in sheet 1

Based on a criteria only A2, A3, A4 are applicable.

So the count value is 3

Step 1: I need to filter the criteria & get the count value as 3. Step 2: Based on count value need to insert rows in another sheet (like currently value is 3, so need to insert 3 empty rows)

Sub Test()
Dim arr, arr2, count%, criteria$
criteria = "place your criteria"
With Sheet(1)
    arr = Application.Transpose(.Range("A1:A10"))
    arr2 = arr
    count = 0
    For i = LBound(arr) To UBound(arr)
        If arr(i) = criteria Then
            arr2(i) = arr(i)
            count = count + 1
        End If
    Next i
End With

If x > 0 Then
    ReDim Preserve arr(1 To x)
    With Sheet(2)
        .Rows(1).EntireRow.Resize(count).Insert 'rows 1 or the row you want
    End With
End If
'Note you'vegot the filtered data in arr2
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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