Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default WorksheetFunction.Sumproduct(syntax...

Thanks for any advice you may give
Can anyone please advise on the syntax for the arguments in the above
function?
I've tried: ?Application.WorksheetFunction.Sumproduct(2,3) .. expecting to
result with 6 but get the error message: "Unable to get the property of the
worksheet function class"
--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default WorksheetFunction.Sumproduct(syntax...

David,

Evaluate it

?evaluate("SumProduct(2,3)")

--

HTH

RP

"David" wrote in message
...
Thanks for any advice you may give
Can anyone please advise on the syntax for the arguments in the above
function?
I've tried: ?Application.WorksheetFunction.Sumproduct(2,3) .. expecting to
result with 6 but get the error message: "Unable to get the property of

the
worksheet function class"
--
David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default WorksheetFunction.Sumproduct(syntax...

?Application.WorksheetFunction.Sumproduct(array(2) ,array(3))
6

--
Regards,
Tom Ogilvy

"David" wrote in message
...
Thanks for any advice you may give
Can anyone please advise on the syntax for the arguments in the above
function?
I've tried: ?Application.WorksheetFunction.Sumproduct(2,3) .. expecting to
result with 6 but get the error message: "Unable to get the property of

the
worksheet function class"
--
David



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default WorksheetFunction.Sumproduct(syntax...

Tom & Bob,
Thanks for your help. I'm still floundering though ...
I'm trying to populate a Crosstab summary of a database using VBA arrays and
then transferring the result back to the worksheet. Please have a look at the
code below for me. The WorksheetFunction.Sumproduct arguments seem to be the
sticking point:

Sub PopulateCrossTab()
'Count ocurences of Colour and Price Code _
combinations in database
Dim Field_ColourData As Variant
Dim Field_PriceCodeData As Variant
Dim CrosstabRowHeader As Variant
Dim CrosstabColHeader As Variant
Dim TempArray() As Variant

'Load arrays
Field_ColourData = Range("B12:B23")
Field_PriceCodeData = Range("C12:C23")
CrosstabRowHeader = _
Range("Crosstab").Resize(, 1).Offset(, -1)
CrosstabColHeader = _
Range("Crosstab").Resize(1).Offset(-1)

'Use Sumproduct to calculate Crosstab values _
and store in TempArray
ReDim TempArray(1 To UBound(CrosstabRowHeader, 1), _
1 To UBound(CrosstabColHeader, 2))
For r = 1 To UBound(CrosstabRowHeader, 1)
For c = 1 To UBound(CrosstabColHeader, 2)
TempArray(r, c) = _
WorksheetFunction.SumProduct(--(CrosstabColHeader(c) =
Field_ColourData), _
--(CrosstabRowHeader(r) = Field_PriceCodeData))
Next
Next

'Transfer TempArray to worksheet
Range("Crosstab") = TempArray
End Sub


"Tom Ogilvy" wrote:

?Application.WorksheetFunction.Sumproduct(array(2) ,array(3))
6


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default WorksheetFunction.Sumproduct(syntax...

David,

I don't see where CrosstabRowHeader and CrosstabColHeader become arrays, as
far as I can see they are ranges.

You didn't do what either Tom or I suggested, so how would you expect it to
work. If you use Evaluate, that should work, but you will need to use Range
strings, and if the value to be tested against is a string, you will need to
add quotes around the variable in the evaluate statement.
--

HTH

RP

"David" wrote in message
...
Tom & Bob,
Thanks for your help. I'm still floundering though ...
I'm trying to populate a Crosstab summary of a database using VBA arrays

and
then transferring the result back to the worksheet. Please have a look at

the
code below for me. The WorksheetFunction.Sumproduct arguments seem to be

the
sticking point:

Sub PopulateCrossTab()
'Count ocurences of Colour and Price Code _
combinations in database
Dim Field_ColourData As Variant
Dim Field_PriceCodeData As Variant
Dim CrosstabRowHeader As Variant
Dim CrosstabColHeader As Variant
Dim TempArray() As Variant

'Load arrays
Field_ColourData = Range("B12:B23")
Field_PriceCodeData = Range("C12:C23")
CrosstabRowHeader = _
Range("Crosstab").Resize(, 1).Offset(, -1)
CrosstabColHeader = _
Range("Crosstab").Resize(1).Offset(-1)

'Use Sumproduct to calculate Crosstab values _
and store in TempArray
ReDim TempArray(1 To UBound(CrosstabRowHeader, 1), _
1 To UBound(CrosstabColHeader, 2))
For r = 1 To UBound(CrosstabRowHeader, 1)
For c = 1 To UBound(CrosstabColHeader, 2)
TempArray(r, c) = _
WorksheetFunction.SumProduct(--(CrosstabColHeader(c) =
Field_ColourData), _
--(CrosstabRowHeader(r) = Field_PriceCodeData))
Next
Next

'Transfer TempArray to worksheet
Range("Crosstab") = TempArray
End Sub


"Tom Ogilvy" wrote:

?Application.WorksheetFunction.Sumproduct(array(2) ,array(3))
6






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default WorksheetFunction.Sumproduct(syntax...

Sumproduct, when used in VBA is looking for array arguments. You are trying
to build arrays, but that only works in a worksheet. You will need to use
evaluate to use that type of construct or build the arrays before providing
them to sumproduct.

--
Regards,
Tom Ogilvy

"David" wrote in message
...
Tom & Bob,
Thanks for your help. I'm still floundering though ...
I'm trying to populate a Crosstab summary of a database using VBA arrays

and
then transferring the result back to the worksheet. Please have a look at

the
code below for me. The WorksheetFunction.Sumproduct arguments seem to be

the
sticking point:

Sub PopulateCrossTab()
'Count ocurences of Colour and Price Code _
combinations in database
Dim Field_ColourData As Variant
Dim Field_PriceCodeData As Variant
Dim CrosstabRowHeader As Variant
Dim CrosstabColHeader As Variant
Dim TempArray() As Variant

'Load arrays
Field_ColourData = Range("B12:B23")
Field_PriceCodeData = Range("C12:C23")
CrosstabRowHeader = _
Range("Crosstab").Resize(, 1).Offset(, -1)
CrosstabColHeader = _
Range("Crosstab").Resize(1).Offset(-1)

'Use Sumproduct to calculate Crosstab values _
and store in TempArray
ReDim TempArray(1 To UBound(CrosstabRowHeader, 1), _
1 To UBound(CrosstabColHeader, 2))
For r = 1 To UBound(CrosstabRowHeader, 1)
For c = 1 To UBound(CrosstabColHeader, 2)
TempArray(r, c) = _
WorksheetFunction.SumProduct(--(CrosstabColHeader(c) =
Field_ColourData), _
--(CrosstabRowHeader(r) = Field_PriceCodeData))
Next
Next

'Transfer TempArray to worksheet
Range("Crosstab") = TempArray
End Sub


"Tom Ogilvy" wrote:

?Application.WorksheetFunction.Sumproduct(array(2) ,array(3))
6




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default WorksheetFunction.Sumproduct(syntax...

Tom & Bob,
Thanks again for your helpful response.
I'm taking your advice and building arrays to be processed by
WorksheetFunction.sumproduct. Currently, the content of the arrays to be
processed is boolian True or False. I'm asking sumproduct to do the
equivalent of:
?Application.WorksheetFunction.Sumproduct(array(Tr ue,True),array(True,False))
which results in zero instead of the required result of 1 in this case.
I know I could use an 'if' structure when building the arrays to get 1s & 0s
(instead of True, False) and then get the expected result. For interest
though, is it possible to coerce the boolians to 1 or 0 as with the worksheet
methods?
--
David

"Tom Ogilvy" wrote:

Sumproduct, when used in VBA is looking for array arguments. You are trying
to build arrays, but that only works in a worksheet. You will need to use
evaluate to use that type of construct or build the arrays before providing
them to sumproduct.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default WorksheetFunction.Sumproduct(syntax...

Declare your arrays as Long

Sub TestSumProduct()
Dim Arr1(1 To 10) As Long
Dim arr2(1 To 10) As Long
For i = 1 To 10
If Rnd() 0.5 Then
Arr1(i) = True
Else
Arr1(i) = False
End If
If Rnd() 0.5 Then
arr2(i) = True
Else
arr2(i) = Fale
End If
Next
MsgBox WorksheetFunction.SumProduct(Arr1, arr2)
End Sub

--
Regards,
Tom Ogilvy



"David" wrote in message
...
Tom & Bob,
Thanks again for your helpful response.
I'm taking your advice and building arrays to be processed by
WorksheetFunction.sumproduct. Currently, the content of the arrays to be
processed is boolian True or False. I'm asking sumproduct to do the
equivalent of:

?Application.WorksheetFunction.Sumproduct(array(Tr ue,True),array(True,False)
)
which results in zero instead of the required result of 1 in this case.
I know I could use an 'if' structure when building the arrays to get 1s &

0s
(instead of True, False) and then get the expected result. For interest
though, is it possible to coerce the boolians to 1 or 0 as with the

worksheet
methods?
--
David

"Tom Ogilvy" wrote:

Sumproduct, when used in VBA is looking for array arguments. You are

trying
to build arrays, but that only works in a worksheet. You will need to

use
evaluate to use that type of construct or build the arrays before

providing
them to sumproduct.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
application.worksheetfunction. <function (syntax) Peter[_21_] Excel Programming 3 September 1st 04 08:24 PM
Application.WorksheetFunction.Index syntax LJones[_2_] Excel Programming 3 August 4th 04 12:13 PM
Syntax for WorksheetFunction Match Hardy[_3_] Excel Programming 1 June 4th 04 11:33 AM
Syntax for WorksheetFunction Mike Fogleman Excel Programming 3 March 1st 04 09:13 PM
WorkSheetFunction.CountIf & WorkSheetFunction.SumIf with 2 conditions? Etien[_2_] Excel Programming 3 January 13th 04 04:07 PM


All times are GMT +1. The time now is 10:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"