View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Another rascally VBA SUMPRODUCT issue

"Vacuum Sealed" wrote:
''used syntax that failed envoking ( Type MisMatch Error 13 ):
''Set mytexp = ccell.offset(0, -2).value


Probably because ccell is not set before that statement, AFAIK.

But perhaps you meant to put or apply this comment inside the For Each
statement.

In that case, the problem is that ccell.offset(0, -2).value is a value
(number, text, etc), not an object. The Set statement is specifically for
creating object references.

Perhaps you should simply omit the word Set; that is, make it a normal
assignment statement. But since you declared mytexp as Range, perhaps you
should write:

Set mytexp = ccell.offset(0, -2)


"Vacuum Sealed" wrote:
.Value = WorksheetFunction.SumProduct((mysYear = mytYear) * (mysMonth =
mytMonth) * (mysEmp = mytEmp) * (mysExp = mytExp) * (mysAmt))


Syntax like (mysYear = mytYear) works in Excel because Excel creates an
array of values. Likewise for syntax like x*y, where x and y are ranges or
arrays.

VBA does not have that capability. Instead, you must create a VBA array of
values yourself.

Also note that in Excel, TRUE is 1; but in VBA, True is -1. In your
example, it makes no difference because you are multiplying an even number
(4) of conditional expressions. But if you multipy an odd number (e.g. 3),
the result will be -1 instead of 1, which is probably not what you intended.