View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default VBA and the SumProduct Function

oops, forgot that.

You could give this a try (I have tested it as best I could)

With Application 'xlApp
Set rng1 = .Worksheets(shtref).Range(colrng)
Set rng2 = .Worksheets(shtref).Range(rngref)
.Range("j15") = Evaluate("SumProduct((" & rng1.Address &
"=""89298"")*" & _
"(" & rng2.Address & "0))") + _
.WorksheetFunction.CountIf(.Worksheets("Dec
Contract").Range(colrng), "89298")
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Frank Kabel" wrote in message
...
Hi
using this kind o Sumproduct syntax is not possible within VBA. In VBA you
can only use the 'classic' Sumproduct syntax: If you need to use SP to
conditional count/sum you have to use Evaluate within VBA

--
Regards
Frank Kabel
Frankfurt, Germany
"Jeff" schrieb im Newsbeitrag
...
I am trying to make this comparison work;
xlApp.Range("j15") =

xlApp.WorksheetFunction.SumProduct(--(xlApp.Worksheets(ShtRef).Range(ColRng)
= "89298"), --(xlApp.Worksheets(ShtRef).Range(rngref) 0))
'xlApp.WorksheetFunction.CountIf(xlApp.Worksheets( ShtRef).Range(ColRng),
"89298") + xlApp.WorksheetFunction.CountIf(xlApp.Worksheets(" Dec
Contract").Range(ColRng), "89298")

Variables for range and sheet names are correct and work in many other
situations so I know its not them.

I want to set a field equal to the number of times both criteria match.

If
I
plug it into the cell manually with out the Worksheets. etc syntax and

use
the Range:Range notation it works on the range.

Any Ideas on what I'm doing wrong