Excel Autofill macro for different data cells

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

1 response

rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
20 Aug 2010 à 08:17
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