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

I am trying to find the number of days between two date
using the following formula: =IF(D2=(DATEVALUE
("1986/1/1")),(DATEVALUE("2004/12/15")-I2),(DATEVALUE
("2004/12/15")-D2)) in a macro. Here is the code in the
macro:
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(DATEVALUE
(""2005/01/01"")-RC[3]),(DATEVALUE(""2005/01/01"")-RC[-
2]))"
I need to have the 2nd and 3rd dates be dynamic when I
run the script and not have them hardcoded. The 1986/1/1
date will always be the same date. I have tried the
following code:
vardate = Right(Date, 4) & "/" & Month(Date) & "/1"
DateValueUS = Application.Evaluate("DateValue(""" &
vardate & """)")
' ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(DateValue
(DATEVALUEUS)-RC[3]),(DATEVALUEUS-RC[-2]))"
but it does not work. Does anybody have a solution to
populate the column with the number of days between two
dates? Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Using DateValue function

Try:-
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(DateValue(" & DATEVALUEUS &
")-RC[3]),(DATEVALUE(" & DATEVALUEUS & ")-RC[-2]))"

Sharad

"Ralph Elmerick" wrote in message
...
I am trying to find the number of days between two date
using the following formula: =IF(D2=(DATEVALUE
("1986/1/1")),(DATEVALUE("2004/12/15")-I2),(DATEVALUE
("2004/12/15")-D2)) in a macro. Here is the code in the
macro:
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(DATEVALUE
(""2005/01/01"")-RC[3]),(DATEVALUE(""2005/01/01"")-RC[-
2]))"
I need to have the 2nd and 3rd dates be dynamic when I
run the script and not have them hardcoded. The 1986/1/1
date will always be the same date. I have tried the
following code:
vardate = Right(Date, 4) & "/" & Month(Date) & "/1"
DateValueUS = Application.Evaluate("DateValue(""" &
vardate & """)")
' ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(DateValue
(DATEVALUEUS)-RC[3]),(DATEVALUEUS-RC[-2]))"
but it does not work. Does anybody have a solution to
populate the column with the number of days between two
dates? Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Using DateValue function

Thanks Sharad. I tried that and now I get
DateValueUS = 38353.
=IF(D2=(DATEVALUE("1986/1/1")),(DATEVALUE(38353)-I2),
(DATEVALUE(38353)-D2))
Which is a step close in that now I indeed get the value
for the DateValue, but it does not make the calculations
and substitute in the subtraction of the two dates.
-----Original Message-----
Try:-
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(DateValue

(" & DATEVALUEUS &
")-RC[3]),(DATEVALUE(" & DATEVALUEUS & ")-RC[-2]))"

Sharad

"Ralph Elmerick" wrote in

message
...
I am trying to find the number of days between two date
using the following formula: =IF(D2=(DATEVALUE
("1986/1/1")),(DATEVALUE("2004/12/15")-I2),(DATEVALUE
("2004/12/15")-D2)) in a macro. Here is the code in

the
macro:
ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(DATEVALUE
(""2005/01/01"")-RC[3]),(DATEVALUE(""2005/01/01"")-RC[-
2]))"
I need to have the 2nd and 3rd dates be dynamic when I
run the script and not have them hardcoded. The

1986/1/1
date will always be the same date. I have tried the
following code:
vardate = Right(Date, 4) & "/" & Month(Date) & "/1"
DateValueUS = Application.Evaluate("DateValue(""" &
vardate & """)")
' ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(DateValue
(DATEVALUEUS)-RC[3]),(DATEVALUEUS-RC[-2]))"
but it does not work. Does anybody have a solution to
populate the column with the number of days between two
dates? Thanks.



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using DateValue function

Sharad Thanks.
I tried your suggestion and now I get
=IF(D2=(DATEVALUE("1986/1/1")),(DATEVALUE(38353)-I2),(DATEVALUE(38353)-D
2))
in the field with #VALUE in the field. The DateValueUS is indeed 38353
so we have made progress it just does not provide the value I need for
the number of days. It is not making the subtraction between the dates.

Thanks



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Using DateValue function

Well Ralph I made a mistake makeing it to work as DateValue(DateValueUS).
Since DaveValueUS is already date value, again DateValue() is causing the
error.

SO try below:

ActiveCell.FormulaR1C1 = _
"=IF(RC[-2]=(DATEVALUE(""1986/1/1"")),(" & DATEVALUEUS &
"-RC[3]),(" & DATEVALUEUS & "-RC[-2]))"
Sharad
"Ralph Elmerick" wrote in message
...
Sharad Thanks.
I tried your suggestion and now I get
=IF(D2=(DATEVALUE("1986/1/1")),(DATEVALUE(38353)-I2),(DATEVALUE(38353)-D
2))
in the field with #VALUE in the field. The DateValueUS is indeed 38353
so we have made progress it just does not provide the value I need for
the number of days. It is not making the subtraction between the dates.

Thanks



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using DateValue function

Thank you so much that does the trick. It works perfectly. This list
is the greatest.

Ralph Elmerick

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Help with DateValue function (part 2) Pank New Users to Excel 4 March 30th 07 08:50 AM
Help with DateValue function. Pank New Users to Excel 7 March 29th 07 02:04 PM
Help With DATEVALUE Dick Frederick Excel Worksheet Functions 3 January 28th 07 09:18 PM
datevalue LarryTheK Excel Worksheet Functions 8 July 23rd 05 03:24 AM
Conditional Sum and DATEVALUE function Vlad Excel Worksheet Functions 2 June 14th 05 05:00 PM


All times are GMT +1. The time now is 01:29 PM.

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

About Us

"It's about Microsoft Excel"