Link to home
Start Free TrialLog in
Avatar of doolinn
doolinnFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel: Automatically Fill Gaps Based on Cells Above

How do I automatically fill in the gaps in a column based on the values in the cell above.
Eg Cell A1 says "MR X", Cell A10 says "Mr Y" and Cell A20 says "Mr Z"
What is the macro that would automatically fill down to show the following ( I need a macro as Ithere is too much data to do a manual fill down). Thanks!

A1 Mr X
A2 Mr X
A3 Mr X
A4 Mr X
A5 Mr X
A6 Mr X
A7 Mr X
A8 Mr X
A9 Mr X
A10 Mr Y
A11 Mr Y
etc etc etc etc...





ASKER CERTIFIED SOLUTION
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use this macro if your column is large.
Sub FillGaps()
If Selection.Cells(1, 1) = "" Then
    MsgBox "First cell is empty!", vbCritical
Exit Sub
End If
For Each c In Selection
    If c.Value = "" Then
        c.Value = c.Offset(-1, 0).Value
    End If
Next
End Sub

Open in new window

saurabh726,
Your solution is cool. I didn't know about it.