View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Need help wiht a macro for autofill rows

10915 didn't have enough data to keep each group with 22 rows.

But this worked for me.

Option Explicit
Sub testme()

Dim myFormulaRng As Range
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim HowManyPerGroup As Long

With Worksheets("sheet1")
Set myFormulaRng = .Range("H2:L2")
FirstRow = 2
LastRow = 10915
'or use the last filled in row in column A??
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

HowManyPerGroup = 23

For iRow = 2 To LastRow Step HowManyPerGroup
myFormulaRng.Copy _
Destination:=.Cells(iRow, "H").Resize(HowManyPerGroup - 1)
Next iRow
End With

End Sub


But I did have to go back to clean up the extra rows at the bottom of that last
group.

And the code expects that H2:L2 have the formulas in each cell.

klafert wrote:

I have a spreadsheet that has 10915 lines. I am copying the same formula
from row 2 - columns H2..L2 to the next 21 rows then there will be one blank
row and I will copy the same columns for the next 21 rows - blank row again
and so on.

Example:

I highlight row 2 (column H2-L2) Fill down H2:L2 to h23:L23 then I have one
blank row and then I would copy H2-L2 thru H23-l23 to h25-L46 - Hope that is
clear enough for somebody to understand if not let me know.


--

Dave Peterson