Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default DATE IN COMPUTATION

I tried without success to compute declaring date as shown below. How
do I declare dates correctly so the formula will compute?

Dim dt, lp1, yb As Date

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)"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default DATE IN COMPUTATION

Hi
You want
Dim dt as Date, lp1 as Date, yb As Date

Your syntax effectively declares dt and lp1 as variants.
This may still not fix your formulae though!
regards
Paul

On Feb 12, 1:28*pm, sylink wrote:
I tried without success to compute declaring date as shown below. How
do I declare dates correctly so the formula will compute?

Dim dt, lp1, yb As Date

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)"


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default DATE IN COMPUTATION

See inline comments...

I tried without success to compute declaring date as shown below. How
do I declare dates correctly so the formula will compute?

Dim dt, lp1, yb As Date


The above statement is not doing what you think it is. Only yb is being
declared as a Date; 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 As Date, lp1 As Date, yb As Date

or do it this way...

Dim dt As Date
Dim lp1 As Date
Dim yb As Date

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default DATE IN COMPUTATION

On Feb 12, 3:41 pm, "Rick Rothstein \(MVP - VB\)"
wrote:
See inline comments...

I tried without success to compute declaringdateas shown below. How
do I declare dates correctly so the formula will compute?


Dim dt, lp1, yb AsDate


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



Thanks Rick for the post. The code ran quite alright but a slight
hitch occurred. It does not produce the correct no. of days within a
given range. For instance,
CStr(dt) & "-RC[-7] gives over 43,000 days instead of 30 days. The
RC[-7] contains the date 01/01/2008

Is there a way to work around this problem? Is the date serial
declaration ok?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default DATE IN COMPUTATION

See inline comments...

I tried without success to compute declaringdateas shown below. How
do I declare dates correctly so the formula will compute?


Dim dt, lp1, yb AsDate


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



Thanks Rick for the post. The code ran quite alright but a slight
hitch occurred. It does not produce the correct no. of days within a
given range. For instance,
CStr(dt) & "-RC[-7] gives over 43,000 days instead of 30 days. The
RC[-7] contains the date 01/01/2008

Is there a way to work around this problem? Is the date serial
declaration ok?


I'm not sure what the problem is as I do not recognize what your formula is
attempting to do nor what it expects its inputted arguments to be. If you
can give us a background on "what is what" with it, perhaps someone might be
able to offer specific advice.

Rick



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default DATE IN COMPUTATION

On Feb 14, 2:36 am, "Rick Rothstein \(MVP - VB\)"
wrote:
See inline comments...


I tried without success to compute declaringdateas shown below. How
do I declare dates correctly so the formula will compute?


Dim dt, lp1, yb AsDate


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


Thanks Rick for the post. The code ran quite alright but a slight
hitch occurred. It does not produce the correct no. of days within a
given range. For instance,
CStr(dt) & "-RC[-7] gives over 43,000 days instead of 30 days. The
RC[-7] contains thedate01/01/2008


Is there a way to work around this problem? Is thedateserial
declaration ok?


I'm not sure what the problem is as I do not recognize what your formula is
attempting to do nor what it expects its inputted arguments to be. If you
can give us a background on "what is what" with it, perhaps someone might be
able to offer specific advice.

Rick



Ok, the formula is designed to compute interest on a given amount for
a given period. So basically the challenge is in obtaining the
duration from two given dates as shown above.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default DATE IN COMPUTATION

"sylink" wrote in message
...
On Feb 14, 2:36 am, "Rick Rothstein \(MVP - VB\)"
wrote:
See inline comments...


I tried without success to compute declaringdateas shown below. How
do I declare dates correctly so the formula will compute?


Dim dt, lp1, yb AsDate


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


Thanks Rick for the post. The code ran quite alright but a slight
hitch occurred. It does not produce the correct no. of days within a
given range. For instance,
CStr(dt) & "-RC[-7] gives over 43,000 days instead of 30 days. The
RC[-7] contains thedate01/01/2008


Is there a way to work around this problem? Is thedateserial
declaration ok?


I'm not sure what the problem is as I do not recognize what your formula

is
attempting to do nor what it expects its inputted arguments to be. If

you
can give us a background on "what is what" with it, perhaps someone

might be
able to offer specific advice.

Rick



Ok, the formula is designed to compute interest on a given amount for
a given period. So basically the challenge is in obtaining the
duration from two given dates as shown above.



I'd say the challenge for other readers is to understand what you want!

Why not manually enter the correct formula. Ensure the cell is selected, in
the Immediate window type
?activecell.formular1c1
hit enter and post the result. Also include the address of the cell together
with the values of any other referenced cells.

In the meantime, some ideas for including dates in string formulas

Sub test()
Dim sF As String
Dim dt As Date

dt = Date
sF = "=DATE(" & Format(dt, "YYYY, m, d") & ") + RC[-1]"
'' or if date can be hard coded
' sF = "=DATE(2008, 2, 14) + RC[-1]"

Range("A1") = 7
Range("B1").FormulaR1C1 = sF

dt = Date
sF = "=" & CLng(dt) + 7 & "-RC[-1]"
Range("A2") = Date

Range("B2").FormulaR1C1 = sF
Range("B2").ClearFormats
End Sub

Regards,
Peter T


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
percentage computation Excel Excel Discussion (Misc queries) 2 December 3rd 08 08:34 PM
Time Computation KenP Excel Discussion (Misc queries) 2 February 15th 07 03:53 PM
What type of pc is best for computation mikecupertino Excel Discussion (Misc queries) 3 February 1st 07 06:25 AM
Automatic Date Computation. JayD[_2_] Excel Programming 1 February 24th 05 07:05 PM
Help wanted with computation Srikanth Ganesan[_2_] Excel Programming 0 September 1st 04 10:04 PM


All times are GMT +1. The time now is 09:45 AM.

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"