ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   formula in VBA (https://www.excelbanter.com/excel-programming/413931-formula-vba.html)

Dave[_79_]

formula in VBA
 
Is the Friday afternoon?
I'm trying to create a formula in VBA. The formula is:
=IF(I3<"",IF(J3<"",SUM(J3:L3)*I3+M3,""),"")
I've written the code, but VBA is not accepting it. So far I have:
..Cells(lNextRow, "N").Formula = "=IF(I" & lNextRow & "<"""","IF(J" &
lNextRow & "<"""","SUM(J" & lNextRow & ":L" & lNextRow & ")*I" & lnextrow
&"+M" & lnextrow & ",""""),"""")"

But it's in red. I can't see what's wrong. Does anyone see it?

Tim Zych

formula in VBA
 
..Cells(lNextRow, "N").Formula = _
"=IF(I" & lnextrow & "<"""",IF(J" & lnextrow & _
"<"""",SUM(J" & lnextrow & ":L" & lnextrow & _
")*I" & lnextrow & "+M" & lnextrow & ",""""),"""")"

Another way to embed double-quotes is to use a variable or constant. Can be
easier to write and debug, IMO.

Const DQ As String = """"

..Cells(lNextRow, "N").Formula = _
"=IF(I" & lnextrow & "<" & DQ & DQ & _
",IF(J" & lnextrow & "<" & DQ & DQ & _
",SUM(J" & lnextrow & ":L" & lnextrow & ")*I" & _
lnextrow & "+M" & lnextrow & "," & DQ & DQ & ")," & DQ & DQ & ")"


--
Tim Zych
www.higherdata.com
Compare data in Excel and find differences with Workbook Compare
A free, powerful, flexible Excel utility



"Dave" wrote in message
. ..
Is the Friday afternoon?
I'm trying to create a formula in VBA. The formula is:
=IF(I3<"",IF(J3<"",SUM(J3:L3)*I3+M3,""),"")
I've written the code, but VBA is not accepting it. So far I have:
.Cells(lNextRow, "N").Formula = "=IF(I" & lNextRow & "<"""","IF(J" &
lNextRow & "<"""","SUM(J" & lNextRow & ":L" & lNextRow & ")*I" & lnextrow
&"+M" & lnextrow & ",""""),"""")"

But it's in red. I can't see what's wrong. Does anyone see it?




salgud

formula in VBA
 
On Fri, 11 Jul 2008 14:31:56 -0700, Tim Zych wrote:

.Cells(lNextRow, "N").Formula = _
"=IF(I" & lnextrow & "<"""",IF(J" & lnextrow & _
"<"""",SUM(J" & lnextrow & ":L" & lnextrow & _
")*I" & lnextrow & "+M" & lnextrow & ",""""),"""")"


Thanks!


All times are GMT +1. The time now is 08:51 AM.

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