Product sum for min, max and the colored cells in VBA

bilbon

Board Regular
Joined
Dec 19, 2011
Messages
83
Hi
Someone who can help me figure out the product sum for min, max and the colored cells in A2:C9.
The coloured cells have a colour index of 15 and 40.
Preferably VBA code

/Bilbon




<colgroup><col span="3"><col><col><col></colgroup><tbody></tbody>

ABCMinMaxColored cells
0,910,971,210,367,850,98
1,180,891,00
1,231,000,87
0,920,911,21
0,811,241,67
0,871,131,33
1,020,871,12
0,921,111,50

<colgroup><col span="3"><col><col><col></colgroup><tbody>
</tbody>
 
Hi DanteAmor


Min and Max work everywhere in the blade but UDF_Colored cells only in the columns A:C,
if I move the data to eg. H:J so it gives #VALUE ! Error for UDF_Colored cells.

/Bilbon
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Code:
Function udf_colored_cells(rng As Range)


[COLOR=#0000ff]    For i = 1 To rng.Rows.Count[/COLOR]
[COLOR=#0000ff]        For j = 1 To rng.Columns.Count[/COLOR]
            If rng.Cells(i, j).Interior.ColorIndex = 15 Or rng.Cells(i, j).Interior.ColorIndex = 40 Then
                If pCol = 0 Then pCol = rng.Cells(i, j).Value Else pCol = pCol * rng.Cells(i, j).Value
            End If
        Next
    Next
    udf_colored_cells = pCol
    
End Function
 
Upvote 0
Hi DanteAmor


Thank you for taking the time.
Now the code works perfectly.
Very grateful


/Bilbon
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,602
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top