Forum Discussion
NLepley
Dec 06, 2022Copper Contributor
Macro formula help
I am trying to create a macro to populate future dates once a location and date are entered into a row. I enter the address and dig date then framing is +15 days from dig date, RI is +35 days from di...
HansVogelaar
Dec 06, 2022MVP
If you prefer VBA code:
Right-click the sheet tab.
Select 'View Code' from the context menu.
Copy the code listed below into the worksheet module.
Switch back to Excel.
Save the workbook as a macro-enabled workbook (.xlsm)
Make sure that you allow macros when you open it.
Private Sub Worksheet_Change(ByVal Target As Range)
Const Interval1 = 15
Const Interval2 = 35
Const Interval3 = 110
Dim rng As Range
Dim dtm As Date
If Not Intersect(Range("B2:B" & Rows.Count), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("B2:B" & Rows.Count), Target)
If rng.Value = "" Or Not IsDate(rng.Value) Or rng.Offset(0, -1).Value = "" Then
rng.Offset(0, 1).Resize(1, 3).ClearContents
Else
dtm = rng.Value
rng.Offset(0, 1).Resize(1, 3).Value = _
Array(dtm + Interval1, dtm + Interval2, dtm + Interval3)
End If
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End SubNLepley
Dec 06, 2022Copper Contributor
thank you so much for your help!