VBA Macro to fill in blank date cells with same preceding date?

Excel Padwan

New Member
Joined
Mar 31, 2014
Messages
2
Hello all,

I received an excel report that uses an unfortunate layout. Here's a sample:

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]1/27/2014[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 1[/TD]
[TD]$10[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 2[/TD]
[TD]$20[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 3[/TD]
[TD]$50[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 4[/TD]
[TD]$40[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]1/27/2014 Total:[/TD]
[TD][/TD]
[TD]$190[/TD]
[/TR]
[TR]
[TD]1/28/2014[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 1[/TD]
[TD]$50[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 2[/TD]
[TD]$40[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 3[/TD]
[TD]$70[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 4[/TD]
[TD]$100[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]1/28/2014 Total:[/TD]
[TD][/TD]
[TD]$260[/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 1[/TD]
[TD]$20[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 2[/TD]
[TD]$70[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 3[/TD]
[TD]$70[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 4[/TD]
[TD]$60[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 5[/TD]
[TD]$50[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]Item 6[/TD]
[TD]$10[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]1/29/2014 Total:[/TD]
[TD][/TD]
[TD]$280[/TD]
[/TR]
</tbody>[/TABLE]

Ideally, I would like it to look like this:
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]1/27/2014[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/27/2014[/TD]
[TD][/TD]
[TD]Item 1[/TD]
[TD]$10[/TD]
[/TR]
[TR]
[TD]1/27/2014[/TD]
[TD][/TD]
[TD]Item 2[/TD]
[TD]$20[/TD]
[/TR]
[TR]
[TD]1/27/2014[/TD]
[TD][/TD]
[TD]Item 3[/TD]
[TD]$50[/TD]
[/TR]
[TR]
[TD]1/27/2014[/TD]
[TD][/TD]
[TD]Item 4[/TD]
[TD]$40[/TD]
[/TR]
[TR]
[TD]1/27/2014[/TD]
[TD]1/27/2014 Total:[/TD]
[TD][/TD]
[TD]$190[/TD]
[/TR]
[TR]
[TD]1/28/2014[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/28/2014[/TD]
[TD][/TD]
[TD]Item 1[/TD]
[TD]$50[/TD]
[/TR]
[TR]
[TD]1/28/2014[/TD]
[TD][/TD]
[TD]Item 2[/TD]
[TD]$40[/TD]
[/TR]
[TR]
[TD]1/28/2014[/TD]
[TD][/TD]
[TD]Item 3[/TD]
[TD]$70[/TD]
[/TR]
[TR]
[TD]1/28/2014[/TD]
[TD][/TD]
[TD]Item 4[/TD]
[TD]$100[/TD]
[/TR]
[TR]
[TD]1/28/2014[/TD]
[TD]1/28/2014 Total:[/TD]
[TD][/TD]
[TD]$260[/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD][/TD]
[TD]Item 1[/TD]
[TD]$20[/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD][/TD]
[TD]Item 2[/TD]
[TD]$70[/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD][/TD]
[TD]Item 3[/TD]
[TD]$70[/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD][/TD]
[TD]Item 4[/TD]
[TD]$60[/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD][/TD]
[TD]Item 5[/TD]
[TD]$50[/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD][/TD]
[TD]Item 6[/TD]
[TD]$10[/TD]
[/TR]
[TR]
[TD]1/29/2014[/TD]
[TD]1/29/2014 Total:[/TD]
[TD][/TD]
[TD]$280[/TD]
[/TR]
</tbody>[/TABLE]

Is there a way to simplify autofilling dates this way? Please note, I do not want to autofill a series. Instead, I'm looking for a way to autofill all the blanks cells between two values so that the blank cells copy the first date.

I am using Excel for Mac 2011.

Any help is much appreciated! Thank you!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
This should work (assuming it was column A with the dates in it).
Code:
Sub fill_dates()
    lastrow = Cells.Find(what:="*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
    Range(Range("A1"), Range("A" & lastrow)).Select
    Dim oRng As Range
    Set oRng = Selection
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.FormulaR1C1 = "=R[-1]C"
        oRng.Copy
        oRng.PasteSpecial Paste:=xlValues
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top