Excel Autofill macro for different data cells

Closed
Mike - Aug 18, 2010 at 11:24 AM
rizvisa1 Posts 4479 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Aug 20, 2010 at 08:17 AM
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

rizvisa1 Posts 4479 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 768
Aug 20, 2010 at 08:17 AM
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
-1