Sumproduct - visible cells

W

whatisyouraddress

Hi,

I trying to to use sumproduct only on visible cells and having a hard
time. I read through many help sites, but can't seem to get it to
work. Here's what I'm trying to do to a much larger file...

A B
1 2 300
2 2 200 (hidden/filtered)
3 3 100

How do I set up a formula to get 2*300 + 3*100 = 900?

Thanks.

tinman
 
V

Vergel Adriano

One way is to do the multiplication in another column, say column C. So you
get

A B C
1 2 300 600
2 2 200 400 (hidden/filtered)
3 3 100 100


Then, SUM all visible rows in column C by using SUBTOTAL.

=SUBTOTAL(109, C1:C3)
 
W

whatisyouraddress

I have several pairs of columns that i need to do this to and was
hoping to not have to add several "total" columns.

tinman
 
J

Jay

A second approach would be to implement this custom function:

Function vis_SumProduct(input1 As Range, input2 As Range)
For Each cl In input1.Cells
If cl.EntireRow.Hidden = False Then
Product = cl * cl.Offset(0, Abs(input2.Column - input1.Column))
vis_SumProduct = vis_SumProduct + Product
End If
Next 'cl
End Function
 
J

Jay

Hi tinman -

Here is an updated version. It simply removes the Abs function from one
line; it's more universal.

Function vis_SumProduct(input1 As Range, input2 As Range)
For Each cl In input1.Cells
If cl.EntireRow.Hidden = False Then
Product = cl * cl.Offset(0, input2.Column - input1.Column)
vis_SumProduct = vis_SumProduct + Product
End If
Next 'cl
End Function
 

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