Hi, I have the following code:
Sub Copy_Rows()
Dim nextrow As Long, i As Long
Application.ScreenUpdating = False
With Worksheets("Baby")
For i = 1 To WorksheetFunction.COUNTIF(Workbooks("Data.xlsx").Worksheets("Sheet1").Columns("A"), Range("BALL")) - 1
Range("RUTH").Copy
Range("Total").Insert Shift:=xlDown
nextrow = .Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & nextrow + 1).PasteSpecial
Next i
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
****
The code works great except for the loop. I am new to VBA so I hope someone can guide me in the right direction.
Essentially, the code is copying the Named Range Baby the number of times the Named Range BALL is in Column A of the Data.xlsx file (less one).
So, in the Named Range BALL is the number 4 - Baby pastes nicely 4x before the Named Range Total, but then the Baby pastes again 3x after the Named Rnage Total. I do not want it to paste the 3 extra times.
Any advice?
Thank you!
Sub Copy_Rows()
Dim nextrow As Long, i As Long
Application.ScreenUpdating = False
With Worksheets("Baby")
For i = 1 To WorksheetFunction.COUNTIF(Workbooks("Data.xlsx").Worksheets("Sheet1").Columns("A"), Range("BALL")) - 1
Range("RUTH").Copy
Range("Total").Insert Shift:=xlDown
nextrow = .Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & nextrow + 1).PasteSpecial
Next i
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
****
The code works great except for the loop. I am new to VBA so I hope someone can guide me in the right direction.
Essentially, the code is copying the Named Range Baby the number of times the Named Range BALL is in Column A of the Data.xlsx file (less one).
So, in the Named Range BALL is the number 4 - Baby pastes nicely 4x before the Named Range Total, but then the Baby pastes again 3x after the Named Rnage Total. I do not want it to paste the 3 extra times.
Any advice?
Thank you!