# Excel macro

I need to do the following inside an excel macro.  I will insert some information on row 2 of a spreadsheet.  I need that row copied and pasted on all even rows of that spreadsheet until the end of the recordset, starting on row 4.   Can anyone help with the code?

IPT
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Not quite sure what you mean by recordset, but the code below will copy row 2 into every even row of the spread sheet up until the last row, row 65536. Hope this helps you out.

Dim i
For i = 4 To 65536 Step 2
Rows("2:2").Select
Selection.Copy
Rows(i & ":" & i).Select
ActiveSheet.Paste
Next i
0
Commented:
These will run about 5x faster (or more) than the code posted above because calculations and screen updates are disabled...  Some display progress in the statusbar so you have an idea of when the macro will complete.

'-------------------------------------
'-------------------------------------
Sub CopyToAllRows()
Dim i
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For i = 4 To 65536 Step 2
rows("2:2").Select
Selection.Copy
rows(i & ":" & i).Select
If i Mod 1000 = 0 Then Application.StatusBar = "Processing Line #: " & i & "     " & "Percent Completed: " & Round((i / 65536) * 100, 2) & "%"
ActiveSheet.Paste
Next i
Application.StatusBar = "Processing Completed!"
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

'-------------------------------------
' Copy only to "used" rows (status bar updates)
'-------------------------------------
Sub CopyToUsedRows()
Dim i
Dim Rng As Range
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set Rng = ActiveSheet.UsedRange
For i = 4 To Rng.rows.Count Step 2
rows("2:2").Select
Selection.Copy
rows(i & ":" & i).Select
If i Mod 1000 = 0 Then Application.StatusBar = "Processing Line #: " & i & "     " & "Percent Completed: " & Round((i / Rng.rows.Count) * 100, 2) & "%"
ActiveSheet.Paste
Next i
Application.StatusBar = "Processing Completed!"
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

'-------------------------------------
'-------------------------------------
Sub CopyToAllRowsNS()
Dim i
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 4 To 65536 Step 2
rows("2:2").Select
Selection.Copy
rows(i & ":" & i).Select
ActiveSheet.Paste
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

'-------------------------------------
' Copy only to "used" rows (no statusbar updates = faster)
'-------------------------------------
Sub CopyToUsedRowsNS()
Dim i
Dim Rng As Range
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set Rng = ActiveSheet.UsedRange
For i = 4 To Rng.rows.Count Step 2
rows("2:2").Select
Selection.Copy
rows(i & ":" & i).Select
ActiveSheet.Paste
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.