Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default DateAdd function

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default DateAdd function

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" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default DateAdd function

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]


Bill wrote:
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dateadd function Dr. Maunuk Excel Discussion (Misc queries) 2 September 28th 07 07:32 AM
dateadd The BriGuy[_2_] Excel Discussion (Misc queries) 1 March 29th 07 06:51 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Using DateAdd Function with cell values loren.pottinger Excel Discussion (Misc queries) 3 August 30th 06 01:10 AM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM


All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"