Reputation: 5
I am trying to pull down the date column to fill in the next sequential dates in the blank cells until the next cell down has a value in it. For example, the blank cells in the highlighted date range should read 3/23/2019 & 3/24/2019 (see screenshot, Column C):
Here is the code that I have crudely put together. But I am so new to this, I am not sure where I am going wrong. In my logic, I execute the code starting from Range C2:
Sub fillInDates()
Dim cellEndRange As Range
Dim cellStartRange As Range
Selection.End(xlDown).Select
ActiveCell.Offset(RowOffset:=-1, ColumnOffset:=0).Activate
cellEndRange = ActiveCell
Selection.End(xlUp).Select
cellStartRange = ActiveCell
cellStartRange.AutoFill Destination:=cellStartRange & cellEndRange
Upvotes: 0
Views: 904
Reputation: 7567
Try, you can work with below.
Sub test()
Dim Ws As Worksheet
Dim vDB As Variant
Dim rngDB As Range
Dim myDate As Date
Dim i As Long
Set Ws = ActiveSheet
With Ws
Set rngDB = .Range("c2", .Range("c" & Rows.Count).End(xlUp))
End With
vDB = rngDB
For i = 1 To UBound(vDB, 1)
If vDB(i, 1) = "" Then
myDate = myDate + 1
vDB(i, 1) = myDate
Else
myDate = vDB(i, 1)
End If
Next i
rngDB = vDB
End Sub
Upvotes: 0
Reputation: 35990
This can be done without VBA code.
=
character+1
to add one day to the date from the cell aboveNow that formula is in all the cells that were previously blank. You can use copy/Paste Values to replace the formula with the values it calculated.
Upvotes: 1