Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Help with DateValue function (part 2) | New Users to Excel | |||
Help with DateValue function. | New Users to Excel | |||
Help With DATEVALUE | Excel Worksheet Functions | |||
datevalue | Excel Worksheet Functions | |||
Conditional Sum and DATEVALUE function | Excel Worksheet Functions |