insert formula

R

rachitprasad

i am writing a macro and would like to insert a formula in like this

Range("H10").FormulaArray =
"=IF((WEEKDAY(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),1)-1)*(WEEKDA­Y(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),1)-7)=0,WORKDAY(DATE(YEAR­(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),-1),DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$­2,DAY(H9)+$D$3))"



the formula works fine.. but the '=' sign inside the quotes is causing
some problems


how do i overcome this.
basically i am trying to add one month to a date. if the result is not
a weekday, then, i shift the result to one previous weekday

thanks a lot in advance
 
N

Niek Otten

<the '=' sign inside the quotes is causing some problems>

What problems? And what does "formula works fine" mean?

--
Kind regards,

Niek Otten


i am writing a macro and would like to insert a formula in like this

Range("H10").FormulaArray =
"=IF((WEEKDAY(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),1)-1)*(WEEKDA­Y(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),1)-7)=0,WORKDAY(DATE(YEAR­(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),-1),DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$­2,DAY(H9)+$D$3))"



the formula works fine.. but the '=' sign inside the quotes is causing
some problems


how do i overcome this.
basically i am trying to add one month to a date. if the result is not
a weekday, then, i shift the result to one previous weekday

thanks a lot in advance
 
G

Guest

s1 =
"=IF((WEEKDAY(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),1)-1)*(WEEKDAY(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),1)-7)=0,WORKDAY(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3),-1),DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3))"
Range("H10").Formula = s1

worked fine for me. This isn't an array formula, so you don't need
formulaArray
 
D

daddylonglegs

Seems to me like you're using an unnecessarily complex formula. This
should achieve the same

=WORKDAY(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DAY(H9)+$D$3+1),-1)

...although I'm not sure what's in D1, D2 and D3. If you're just adding
one month to the date, as you say then aren't D1 and D3 zero?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top