I am in need of assistance with perfecting my current macro.
I have a spreadsheet with 49 account numbers in column A. My objective is to duplicate those 49 account numbers to a certain number of rows. For example, I need account # 654189 to be in column A from row 2-213. Then I need account # 651988 to be duplicated from row 214-426 etc.
I thought that the filldown function would be the most effective way to accomplish this, since I've already written a macro to insert a certain number of blank rows between each account number.
The macro I've written gets the job done with filling down the account numbers, until we get to the last account number. The filldown function doesn't work effectively for that last account number, because there is no other data in column A below it, to stop the fill down.
I'm thinking that I could use the input box from my "insertrows" macro below to dictate how many times each account number is filled down.
Here is my current macro for the filldown:
Sub AcctFillDown()
Dim LR As Long
LR = Cells.Find(What:="", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("A2:A" & LR)
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
.Value = .Value
End With
End Sub
This is the macro I'm using to insert the blank rows
Sub InsertRows()
Dim j As Long, r As Range
j = InputBox("type the number of rows to be inserted")
Set r = Range("A2")
Do
Range(r.Offset(1, 0), r.Offset(j, 0)).EntireRow.Insert
Set r = Cells(r.Row + j + 1, 1)
If r.Offset(1, 0) = "" Then Exit Do
Loop
End Sub
I have a spreadsheet with 49 account numbers in column A. My objective is to duplicate those 49 account numbers to a certain number of rows. For example, I need account # 654189 to be in column A from row 2-213. Then I need account # 651988 to be duplicated from row 214-426 etc.
I thought that the filldown function would be the most effective way to accomplish this, since I've already written a macro to insert a certain number of blank rows between each account number.
The macro I've written gets the job done with filling down the account numbers, until we get to the last account number. The filldown function doesn't work effectively for that last account number, because there is no other data in column A below it, to stop the fill down.
I'm thinking that I could use the input box from my "insertrows" macro below to dictate how many times each account number is filled down.
Here is my current macro for the filldown:
Sub AcctFillDown()
Dim LR As Long
LR = Cells.Find(What:="", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("A2:A" & LR)
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
.Value = .Value
End With
End Sub
This is the macro I'm using to insert the blank rows
Sub InsertRows()
Dim j As Long, r As Range
j = InputBox("type the number of rows to be inserted")
Set r = Range("A2")
Do
Range(r.Offset(1, 0), r.Offset(j, 0)).EntireRow.Insert
Set r = Cells(r.Row + j + 1, 1)
If r.Offset(1, 0) = "" Then Exit Do
Loop
End Sub