PDA

View Full Version : [SOLVED:] COUNTIF code then insert copied cells



ell_
01-21-2018, 09:52 PM
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.

21420

paulked
01-21-2018, 10:18 PM
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

ell_
01-21-2018, 10:30 PM
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?

ell_
01-21-2018, 10:33 PM
Oh nevermind found it! Thanks again!



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

paulked
01-21-2018, 11:27 PM
You're welcome!