|
vbamaster 发表于 2012-4-30 08:00
arr = Application.SumIf(Range("a2:a10000"), Array("B", "C", "G", "R"), Range("B2:B10000"))
我用的 ...
My appology for typing English as I'm at work.
I tried office PC (WINXP + Excel 2003) and I got the same result as what I got from my home PC (WIN7 + Excel 2003).
- Sub test1()
- Dim arr
- arr = Application.SumIf(Range("a2:a10000"), Array("B", "C", "G", "R"), Range("B2:B10000"))
- Debug.Print TypeName(arr)
- Debug.Print arr
- End Sub
复制代码
I got error message: Run-time error '13': Type mismatch
and TypeName(arr) is Variant
- Sub test2()
- Dim arr
- arr = Application.Sum(Application.SumIf(Range("a2:a10000"), Array("B", "C", "G", "R"), Range("B2:B10000")))
- Debug.Print TypeName(arr)
- Debug.Print arr
- End Sub
复制代码- Sub test3()
- Dim arr
- arr = WorksheetFunction.Sum(Application.SumIf(Range("a2:a10000"), Array("B", "C", "G", "R"), Range("B2:B10000")))
- Debug.Print TypeName(arr)
- Debug.Print arr
- End Sub
复制代码
For both test2 and test3 - I got the same and correct results!
TypeName(arr) is Double (in both tests)
Why this happened I've no idea - this could be another interesting topic for anther day. However you should get my point about the difference between Application and Worksheetfunction.
|
|