Excel Autofill macro for different data cells

[Closed]
Report
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-
Hello,

I am looking to create a macro that will enable autofilling different rows with the data in the top cell. Here is an example:

Row Cell
1 Cat
2
3
4 Dog
5
6
7
8 Bird
9
etc.

I want to create a macro that will fill row 2 and 3 in the same colume with "Cat" and rows 5-7 with "Dog" and so forth.

Any ideads? Please help since I have 10000 rows that need this...thanks!

Mike

1 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
768
Try this

Sub FillUp()
Dim lRow As Long
Dim sLastValue As String
    
    lRow = 2
    Do While Cells(lRow, 1) <> ""
        
        If (Cells(lRow, 2) <> "") Then
           sLastValue = Cells(lRow, 2)
        Else
            Cells(lRow, 2) = sLastValue
        End If
    
        lRow = lRow + 1
    Loop
    
End Sub

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!