How to autofill with non consecutive data

Closed
Rich - May 31, 2010 at 08:49 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - May 31, 2010 at 12:37 PM
Hello,


I have a list of customer names and account totals but the customer name is not repeated down the column. For example:

Customer A
blank row
blank row
Customer B
blank row
blank row
blank row
blank row
Customer C
blank row
blank row

I want it to look like this, by some way to autofill:

Customer A
Customer A
Customer A
Customer B
Customer B
Customer B
Customer B
Customer B
Customer C
Customer C
Customer C

I would like to know how I can autofill the blank rows with the customers' name, when I try auto fill it replaces all the other customers names with the name I tried to autofill.

Can anyone please help?!

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 31, 2010 at 12:37 PM
You can try to use a macro for that

Sub FillDown()
Dim lMaxRows As Long
Dim lRow As Long

    ' find max number of rows
    lMaxRows = Cells.Find("*", Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    ' start from row 2 till end of rows
    For lRow = 2 To lMaxRows
    
        ' if the current cell is blank, then put the value of the cell above
        If Cells(lRow, "A") = "" Then Cells(lRow, "A") = Cells(lRow - 1, "A")
         
    Next lRow
    
End Sub
1