Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a date from VBA Function

Status
Not open for further replies.

MrsMope

Technical User
Oct 18, 2004
125
US
Hello,
I am using MS Excel 2002, I want to add one day to a date using the DateAdd function. So I have the following:

Code:
Function Add_A_Day(CellValue As Date)

   Dim LDate As Date
   
   LDate = DateAdd("d", 1, CellValue)
   
End Function

In the cell I want to contain the new value I have
Code:
=Add_A_Day(k2)
The Cell K2 has a value of 01/02/07, the cell is formatted as a date. When I step through the code and I type ?LDate in the immediate window I see 01/03/07, but the value in the cell shows as 01/00/00. Any idea why?

Thanks,
 
Function Add_A_Day(CellValue As Date)
Add_A_Day = DateAdd("d", 1, CellValue)
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Replace LDate by Add_A_Day:
Add_A_Day=DateAdd("d", 1, CellValue)
or simply:
Add_A_Day=CellValue+1

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top