Need help: (VBA Function) Sum cells above until specific interior.color

tears

New Member
Joined
May 13, 2008
Messages
31
Hi,

I'm trying to find an efficient way to sum all cells above the active cell, until it hits a specific cell color. E.g. the function needs to do a reverse loop sum and stop when it hits a cell color.

Any help would be greatly appreciated.
(I have searched all known Excel forums for this to no avail.)

Thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try next UDF
Somewhere put =SUMCELLS(C10,F6)
where F6 is a cell with the same color that the cell where to stop the sum
where C10 is the cell where to start the sum going up in the column

Code:
Option Explicit

Function SUMCELLS(WkRg As Range, RefRg As Range) As Double
Dim I  As Integer
   For I = WkRg.Row To 1 Step -1
      If (Application.IsNumber(Cells(I, WkRg.Column))) Then _
            SUMCELLS = SUMCELLS + Cells(I, WkRg.Column)
      If (Cells(I, WkRg.Column).Interior.Color = RefRg.Interior.Color) Then Exit For
   Next
   
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,849
Messages
6,121,922
Members
449,056
Latest member
denissimo

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