Search code examples
excelvbadateexcel-formulafill

Fill in missing dates


I am working on big data set and manually filling the missing dates is very tedious work. I want to automate this by applying Excel formula or VBA code which can help me fill all these missing dates.

Please have a look at the data below.

input-output missing dates The first table is the input I get, and I want the 2nd table as my output. Yellow cells show the missing dates which should be same as its previous row.


Solution

  • I'd use this function:

    Sub Fill_In_Missing_Dates()
        Dim rng As Range
        Dim cell As Range
        Set rng = ThisWorkbook.Sheets("Sheet1").Range("B2:B11")
        For Each cell In rng
            If cell.Value = vbNullString Then cell.Value = cell.Offset(-1).Value
        Next
    End Sub
    

    Just change Sheet1 and B2:B11 with your actual sheet name and cells.