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:

1/27/2014
Item 1$10
Item 2$20
Item 3$50
Item 4$40
1/27/2014 Total:$190
1/28/2014
Item 1$50
Item 2$40
Item 3$70
Item 4$100
1/28/2014 Total:$260
1/29/2014
Item 1$20
Item 2$70
Item 3$70
Item 4$60
Item 5$50
Item 6$10
1/29/2014 Total:$280

<tbody>
</tbody>

Ideally, I would like it to look like this:
1/27/2014
1/27/2014Item 1$10
1/27/2014Item 2$20
1/27/2014Item 3$50
1/27/2014Item 4$40
1/27/20141/27/2014 Total:$190
1/28/2014
1/28/2014Item 1$50
1/28/2014Item 2$40
1/28/2014Item 3$70
1/28/2014Item 4$100
1/28/20141/28/2014 Total:$260
1/29/2014
1/29/2014Item 1$20
1/29/2014Item 2$70
1/29/2014Item 3$70
1/29/2014Item 4$60
1/29/2014Item 5$50
1/29/2014Item 6$10
1/29/20141/29/2014 Total:$280

<tbody>
</tbody>

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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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