Search code examples
excelvbadatatablecell

Select last non-empty cell in column A --> Fill down empty cells below in column A, based on last non-empty cell in column C --> Repeat


I would like to fill down the last-non empty cell value in Column A in Excel. It should stop filling down once it reaches the count for the last non-empty cell in Column C. Here is an example:

img1

It should look like this:

img2

Would like to repeat this for the last non-empty cell;

img3

This is the closest I've gotten to what I'm looking for, but I don't want to select A2 every time. I would like to select the last non-empty cell in column A each time.

Dim lrowc As Integer

lrowc = SavedData.Cells(Rows.Count, "C").End(xlUp).Row
    SavedData.Range("A2:A" & lrowc).FillDown

Solution

  • Seems to be the same principle as you are using for column C - find the last used cell in A and then use FillDown:

    Sub x()
    
    Dim lrowc As Long, n As Long
    
    With SavedData 'assume defined somewhere
        n = .Cells(Rows.Count, "A").End(xlUp).Row 'last filled cell in A
        lrowc = .Cells(Rows.Count, "C").End(xlUp).Row 'last filled cell in C
        .Range("A" & n & ":A" & lrowc).FillDown
    End With
    
    End Sub