DateAdd function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
Can anybody tell me why the line of code in Capital letters beginning with CMONTHPLUS returns a "mismatch type" error? The variables above this line of code show the appropriate values when I am in the debugging mode. The execution of the macro stops at this line and says "mismatch type". Thanks in advance, Bill

Sub Button12_Click()
Sheet3.Activate
Dim Cmonth As Date
Dim Cmonthplus As Date
Dim thistime As Date
thistime = Date
Cmonth = Range("c7")
If Cmonth < thistime Then
CMONTHPLUS = DateAdd("yyyy", 2, "Cmonth")
Range("c7") = Cmonthplus
End If
End Sub
 
Bill,

In the line of code,

CMONTHPLUS = DateAdd("yyyy", 2, "Cmonth")

you are attempting to add 2 years to the text string value "Cmonth", not the
variable named Cmonth. Change the line to

CMONTHPLUS = DateAdd("yyyy", 2, Cmonth)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


Bill said:
Hello,
Can anybody tell me why the line of code in Capital letters beginning with
CMONTHPLUS returns a "mismatch type" error? The variables above this line
of code show the appropriate values when I am in the debugging mode. The
execution of the macro stops at this line and says "mismatch type". Thanks
in advance, Bill
 
Hi Bill,
CMONTHPLUS = DateAdd("yyyy", 2, "Cmonth")

The DateAdd function is expecting a variable of type Date for the third
argument. You have passed in a String. Get rid of the quotes around Cmonth
and it should work.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
Back
Top