Consulting

Results 1 to 5 of 5

Thread: COUNTIF code then insert copied cells

  1. #1
    VBAX Regular
    Joined
    Nov 2017
    Posts
    22
    Location

    Question COUNTIF code then insert copied cells

    Hi, all

    Is it possible if I apply a code where with every COUNTIF of 10 "3", the "A" will be copied and inserted to the bottom row of the 10th "3"? The code I wrote below is wrong I believe.

    Do Until IsEmpty(Sheet1.Range("A"))
        If Sheet1.Range("A") = Sheet1.Range("A")
            For i = 2 To 6
            Set rn = Sheet1.Range("A1")
            rn.Copy
            rn.Offset(1).Insert Shift:=xlDown
    Loop
    Application.ScreenUpdating = False
    Hereby I attached an Excel file.

    Thank you so much to all.

    Book2.xlsx

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Sub FillA()
        Dim rw As Long, x As Long, lr As Long
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        For x = 1 To lr
            If Cells(x, 1) = "3" Then rw = rw + 1
            If rw = 11 Then
                Cells(1, 1).Copy
                Cells(x, 1).Insert
                rw = 0
            End If
        Next
    End Sub
    Semper in excretia sumus; solum profundum variat.

  3. #3
    VBAX Regular
    Joined
    Nov 2017
    Posts
    22
    Location
    Hi, Paulked

    This works well! Just in case if this code has to change in future, how can I alter this code so that it can copy the whole row and insert the row, instead of cell?

  4. #4
    VBAX Regular
    Joined
    Nov 2017
    Posts
    22
    Location
    Oh nevermind found it! Thanks again!

                Range("Insert range").Copy 'can change to row
                Cells(x, 1).Insert

  5. #5
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    You're welcome!
    Semper in excretia sumus; solum profundum variat.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •