0

I am terrible with coding dates - I would like to add 3 months to a trimmed date. How would I go about this? Coding example below

Dim AuStart As String
Dim AuEnd As String

AuStart = Trim(HE.CurrentHost.TextRC(10, 19, 8)) 'this would be for example 12/09/19
AuEnd = ??? 'this for example if the AuStart = 12/09/19 should be 3/09/19

HE.CurrentHost.PutText AuEnd, 10, 45

Thanks all

braX
  • 11,506
  • 5
  • 20
  • 33
Mikey
  • 5
  • 3
  • AuStart = 12/09/19 should be 3/09/20 ??? – Excel Hero Mar 27 '20 at 01:14
  • 3
    Use the [VBA function](https://stackoverflow.com/a/19815087/4717755) `CDATE` to convert the date string to a real VBA `Date` type. Then use [`DATEADD`](https://www.techonthenet.com/excel/formulas/dateadd.php) to add three months – PeterT Mar 27 '20 at 01:17

2 Answers2

1

You can directly pass the string as well, but should be in any date format, As third argument of the DateAdd function is a variant variable.

Three Month ahead of AuStartDate

Format(DateAdd("m", 3, AuStart),"mm/dd/yyyy")

Three Month Prior of AuStartDate

Format(DateAdd("m", -3, AuStart),"mm/dd/yyyy")

You can Manipulate the date as per your need, This function is Not just limited to this, For More Detail Please check the below link

[https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dateadd-function][1]

Arpan Saini
  • 4,623
  • 1
  • 42
  • 50
0

Like this...

AuEnd = Format(DateAdd("m", 3, DateValue(AuStart)))

Update

You can add the Number Format for the date at the end...

AuEnd = Format(DateAdd("m", 3, DateValue(AuStart)),"mm/dd/yyyy")
Excel Hero
  • 14,253
  • 4
  • 33
  • 40
  • Excel Hero - this worked almost perfectly except it makes AuEnd = 3/6/2020 and i need it to be in the format of 03/06/2020. Is this doable? Thanks so much – Mikey Mar 27 '20 at 17:00
  • @Mikey I updated the answer so that the date is produced in the format you want. – Excel Hero Mar 27 '20 at 17:10