View Full Version : VBA: Multiple Autofill in same column

05-02-2013, 03:20 AM
Dear All,

As a subject it sounds easy, but I have been looking on net, couldn't find multiple autofill.

I have a database in which I need to insert Autofill for multiple coding in the same column, for first coding its easy as below:

Sub Journal()
Dim LR1 As Long
Dim LR2 As Long

LR1 = Sheets("Journal").Range("K" & Rows.Count).End(xlUp).Row
LR2 = Sheets("Journal").Range("J" & Rows.Count).End(xlUp).Row

Range("B3").Formula = "30020400"
Range("B3").AutoFill Range("B3:B" & LR1)

End Sub

Suppose this coding is till 50th Row and for next blank cell in the same column I am using:

Range("B" & Rows.Count).End(xlUp).Offset(1).Formula = "60600050"

I don't know how to start autofill from 51st row till the LR2.

Please help.

05-02-2013, 04:31 AM
I got it right, please see below for future reference:

Sub FillEmpty()
Dim c As Range
Dim LR As Long

LR = Sheets("Journal").Range("C" & Rows.Count).End(xlUp).Row

For Each c In Range("B4:B" & LR)
If IsEmpty(c) Then
c.Offset(-1).Copy c
End If

Next c
End Sub

You just need to call above sub in the end of your main sub.