passing array reference to sumproduct formula-???

P

PBcorn

I have a UDF (see bottom) which finds a particular col header then looks up a
range in that column. I want to pass this range to a sumproduct formula in
another cell:

=SUMPRODUCT(((TRIM($A$8:$A46)="A")+(TRIM($A$8:$A46)="B")+(TRIM($A$8:$A46)="C")+(TRIM($A$8:$A46)="D"))*((TRIM($B$8:$B46)="E")),C$8:C46)

So for the above, C$8:C46 would be replaced by REFR()

REFR works fine, returning the correct range reference, but when i put it in
the sumproduct formula a value error results.

Please help

Thanks

Function REFR(Product As Range, Colhead As Range)

Application.Volatile

Dim c As Range
Dim productstring As String
Dim cs As Integer
Dim rs As Integer
Dim sumthese As Variant

productstring = Product.Value


For Each c In Colhead.Cells

If Trim(c) = Trim(productstring) Then

cs = c.Column
rs = c.Row + 1

Set sumthese = Range(Cells(rs, cs), Cells(rs + 35, cs))

Else: End If

Next c

REFR = sumthese.Address(rowabsolute:=False, columnabsolute:=False)

End Function
 
D

Dave Peterson

Untested:

=SUMPRODUCT(((TRIM($A$8:$A46)="A")
+(TRIM($A$8:$A46)="B")
+(TRIM($A$8:$A46)="C")
+(TRIM($A$8:$A46)="D"))
*((TRIM($B$8:$B46)="E")),
indirect(refr(rng1,rng2)))

(change rng1 and rng2 to the addresses you need)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top