VBA Filldown

Jess709

New Member
Joined
Apr 24, 2015
Messages
20
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
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Re: VBA Filldown Help

This fills the account number as the rows are inserted.

Code:
[color=darkblue]Sub[/color] InsertRows()
    [color=darkblue]Dim[/color] j [color=darkblue]As[/color] [color=darkblue]Long[/color], r [color=darkblue]As[/color] Range
    j = InputBox("type the number of rows to be inserted")
    [color=darkblue]Set[/color] r = Range("A2")
    Application.ScreenUpdating = [color=darkblue]False[/color]
    [color=darkblue]Do[/color]
        DoEvents [color=green]'allows user to escape[/color]
        Range(r.Offset(1, 0), r.Offset(j, 0)).EntireRow.Insert
        r.Offset(1, 0).Resize(j).Value = r.Value
        [color=darkblue]Set[/color] r = Cells(r.Row + j + 1, 1)
        [color=darkblue]If[/color] r.Value = "" [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Do[/color]
    [color=darkblue]Loop[/color]
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top