See inline comments...
I tried without success to compute declaringdateas shown below. How
do I declare dates correctly so the formula will compute?
The above statement is not doing what you think it is. Only yb is being
declared as aDate; both dt and lp1 are being declared as Variants. In
VB/VBA, you must explicitly declare each variable as to its type. So, either
do this...
Dim dt AsDate, lp1 AsDate, yb AsDate
or do it this way...
Dim dt AsDate
Dim lp1 AsDate
Dim yb AsDate
dt = DateSerial(2008, 1, 31)
lp1 = DateSerial(2007, 12, 31)
yb = DateSerial(2008, 1, 1)
Range("R" & z).FormulaR1C1 = "=(((RC[-12]+1)-lp1)*RC[-7]*RC[-4]/
36600)+ ((dt-(yb + 1))*RC[-7]*RC[-4]/36600)"
Can't help you with your actual formula as to whether it does what you want,
but we can help you structure it so that the variables' values are actually
embedded into it. The reason your formula is not working is that you put the
variable names **inside** the quote marks where they are just pieces of text
rather than concatenating the variable names with the surrounding text so
that VBA can see them for the variable that they are. Give this modification
to your statement a try...
Range("R" & z).FormulaR1C1 = "=(((RC[-12]+1)-" & CStr(lp1) & _
")*RC[-7]*RC[-4]/36600)+ ((" & CStr(dt) & _
"-(" & CStr(yb) & " + 1))*RC[-7]*RC[-4]/36600)"
You might be able to get away without encasing the variable names in the
CStr function calls, but I think it is better to explicitly convert the
contained values into text in order to concatenate them as opposed to hoping
VBA with get it right by guessing as to how to coerce your variables'
content.
Rick