DateAdd function shows date from 1900

olorin_117

New Member
Joined
Jan 19, 2022
Messages
18
Office Version
  1. 2019
Platform
  1. Windows
I have run to this weird problem and I really can't understand what is happening.

I have the code below

VBA Code:
Dim tddate As Date
Dim expdate As String
Dim inputdate As String

tddate = Worksheets("Sheet3").Range("pdate").Value
inputdate = TextBox1.Value
expdate = Format(DateAdd("m", 18, tddate), "dd/mm/yyyy")

If inputdate = expdate Then
Range("A1").Value = TextBox1.Value
Else
MsgBox "Input the correct date"
Cancel = True
End If

It compares the user input with the date that MUST be in a textbox...Until yesterday it worked PERFECT with no problems at all

Today that I continued my work on the excel project If I Debug.Print the expdate varieable the date that it shows is 30/06/1901 !!!!!!

PS. If I Debug.Print Now it shows the correct date
PS.2. I am using Excel 2019 but I tried the workbook on a different laptop with Excel 2016 and shows the same thing. (The second try is because I changed my RAM yesterday -every time in my system is correct - and thought I messed up something)
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi,
see if this update to your code does what you want

VBA Code:
    Dim tddate      As Date, expdate As Date
    Dim inputdate   As Variant
   
    inputdate = TextBox1.Value
    If Not IsDate(inputdate) Then Exit Sub Else inputdate = DateValue(inputdate)
   
    tddate = Worksheets("Sheet3").Range("pdate").Value
   
    expdate = DateAdd("m", 18, tddate)
   
    If inputdate = expdate Then
        With Range("A1")
            .Value = inputdate
            .NumberFormat = "dd/mm/yyyy"
        End With
    Else
        MsgBox "Input the correct date", 48, "Invalid Date Entry"
        Cancel = True
    End If

Dave
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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