I have the following formula that works fine:
=IF(L1="",(SUMPRODUCT(--(spc=H1),--(mdate<=IF(K1="","*",K1)),--(msale))),(SUMPRODUCT(--(spc=H1),--(mdate>=K1),--(mdate<=L1),--(msale))))
THe formula is used for many row so I have tried to insert the formula result via VBA but I have a sintax error
Lrow2 = Range("H1").End(xlDown).Row
For X = 1 To Lrow2
Sheets("LC").Range("A" & Lrow) = eVALUATE("=IF(L"& x &"="",(SUMPRODUCT(--(spc=H"& x &"),--(mdate<=IF(K"& x &"="","*",K"& x &")),--(msale))),(SUMPRODUCT(--(spc=H"& x &"),--(mdate>=K"& x &"),--(mdate<=L"& x &"),--(msale))))")
next X
Any suggestion?
Last edited by fabdav; 01-27-2012 at 04:12 AM.
Are you trying to insert the formula into the cell, or only put the result of the formula into the cell?
If the former you need to use the .Formula property of the range and the formula will have to be enclosed in quotes.
If the latter then you can't just quote the formula, you'll have to translate it into VBA first.
Working with a simpler formula - where you're inserting =B2+C2 into each row in A from 2 until the end of the sheet the two options would be:
OrSheets("LC").Range("A" & x).Formula="=SUM(B" & x & "+C" & x &")"
Hope that helps.Sheets("LC").Range("A" & x).Value = WorksheetFunction.Sum(Sheets("LC").Range("B" & x & ":C" & x))
I want to insert the result of the formula.
This is a simpler version but I have i have mismatch error:
For X = 1 To 10
P = Evaluate("=(SUMPRODUCT(--(spc=H" & X & "),--(mdate<=IF(K" & X & "=""," * ",K" & X & ")),--(msale)))")
MsgBox P
Next X
End Sub
Could you use code tags, please?
I think the problem is with your quotation marks. Try:
P = Evaluate("=(SUMPRODUCT(--(spc=H" & X & "),--(mdate<=IF(K" & X & ""="","" * "",K" & X & ")),--(msale)))")
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks