VBA - Adding Days to to Date

Darlie247

New Member
Joined
Apr 2, 2022
Messages
13
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
This is probably super simple, but I'm too new to this coding thing that I can't figure it out

I have dates (dd-mmm-yy) in Column A3 going down (dates will continue to be added) and I want a vba that will add 14 days on to the dates from Column A and calculate them correspondingly into Column E. I also want Column E to be left blank if there is no date in Column A.

Any help/explanation will be greatly appreciated! :)
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Here's one way you could do it:

VBA Code:
Sub Test()

    Dim ws As Worksheet

    Set ws = Worksheets("Sheet1")   'say
    
    With ws.Range("E3:E" & ws.Range("A" & Rows.Count).End(xlUp).Row)
        .Formula = "=IF(A3="""","""",A3+14)"
        .Value = .Value     'optional
        .NumberFormat = "d mmm yyyy"  'your choice
    End With

End Sub
 
Upvote 0
If you wanted the process to happen automatically, you could try this Worksheet_Change event code (put in the Sheet code area of the sheet in question)

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("A:A"), Target) Is Nothing Then
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        Dim lr As Long, i As Long, a, b
        lr = Cells.Find("*", , xlFormulas, , 1, 2).Row
        
        a = Range("A3:E" & lr)
        ReDim b(1 To UBound(a), 1 To 1)
        For i = 1 To UBound(a)
            If IsDate(a(i, 1)) Then b(i, 1) = a(i, 1) + 14
        Next i
        
        Range("E3").Resize(UBound(b)).Value = b
        Range("E3:E" & lr).NumberFormat = "dd-mmm-yy"
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,375
Messages
6,124,578
Members
449,174
Latest member
chandan4057

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