ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   insert formula (https://www.excelbanter.com/excel-programming/361710-insert-formula.html)

[email protected]

insert formula
 
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,DA Y(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,DA Y(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


Niek Otten

insert formula
 
<the '=' sign inside the quotes is causing some problems

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

--
Kind regards,

Niek Otten


wrote in message oups.com...
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,DA Y(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,DA Y(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



Tom Ogilvy

insert formula
 
s1 =
"=IF((WEEKDAY(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DA Y(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

--
Regards,
Tom Ogilvy


" wrote:

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,DA Y(H9)+$D$3),1)-1)*(WEEKDAÂ*Y(DATE(YEAR(H9)+$D$1,MONTH(H9)+$D$2,DA Y(H9)+$D$3),1)-7)=0,WORKDAY(DATE(YEARÂ*(H9)+$D$1,MONTH(H9)+$D$2,D AY(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



daddylonglegs[_37_]

insert formula
 

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?


--
daddylonglegs
------------------------------------------------------------------------
daddylonglegs's Profile: http://www.excelforum.com/member.php...o&userid=30486
View this thread: http://www.excelforum.com/showthread...hreadid=542934



All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com