Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Sumproduct VBA

I have the following code to sum cells by cell color, however i need to take
it one step further by using sum product by cell color. i would like to sum
the numbers in the colored cells and then multiply by other cells that dont
have to have a specific color. can someone please help me out? Thanks
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As
Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult

''''''''''''''''''''''''''''''''''''''
'Written by Ozgrid Business Applications
'www.ozgrid.com
'Sums or counts cells based on a specified fill color.
'''''''''''''''''''''''''''''''''''''''
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If

ColorFunction = vResult
End Function

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200811/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Sumproduct VBA

Hi Brownti

If I understand you corredtly this should do the trick
I created it with Excel 2003.

Public Function ColorSumProduct(rColor As Range, _
rMatch As Range, _
rProduct As Range) As Double
Dim dblResult As Double
Dim lngRows As Long
Dim lngCols As Long
Dim lngRL As Long
Dim lngCL As Long
Dim lngColor As Long

On Local Error GoTo ColorSumProduct_err

lngColor = rColor.Interior.Color
lngRows = rMatch.Rows.Count
lngCols = rMatch.Columns.Count

For lngRL = 1 To lngRows
For lngCL = 1 To lngCols
If rMatch.Cells(lngRL, lngCL).Interior.Color = lngColor
Then
dblResult = dblResult + _
(rMatch.Cells(lngRL, lngCL).Value * _
rProduct.Cells(lngRL, lngCL).Value)
End If
Next
Next

ColorSumProduct = dblResult

Exit Function
ColorSumProduct_err:
Debug.Print Err.Description
End Function

HTH,

Wouter
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Sumproduct VBA

That does the trick! Thanks a ton!

RadarEye wrote:
Hi Brownti

If I understand you corredtly this should do the trick
I created it with Excel 2003.

Public Function ColorSumProduct(rColor As Range, _
rMatch As Range, _
rProduct As Range) As Double
Dim dblResult As Double
Dim lngRows As Long
Dim lngCols As Long
Dim lngRL As Long
Dim lngCL As Long
Dim lngColor As Long

On Local Error GoTo ColorSumProduct_err

lngColor = rColor.Interior.Color
lngRows = rMatch.Rows.Count
lngCols = rMatch.Columns.Count

For lngRL = 1 To lngRows
For lngCL = 1 To lngCols
If rMatch.Cells(lngRL, lngCL).Interior.Color = lngColor
Then
dblResult = dblResult + _
(rMatch.Cells(lngRL, lngCL).Value * _
rProduct.Cells(lngRL, lngCL).Value)
End If
Next
Next

ColorSumProduct = dblResult

Exit Function
ColorSumProduct_err:
Debug.Print Err.Description
End Function

HTH,

Wouter


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200811/1

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
Sumproduct with Condition OR Sumproduct with ADDRESS function - HE gholly Excel Discussion (Misc queries) 2 September 28th 09 05:07 PM
Conditional SUMPRODUCT or SUMPRODUCT with Filters Ted M H Excel Worksheet Functions 4 August 14th 08 07:50 PM
SUMPRODUCT Help Matt Excel Worksheet Functions 4 August 31st 07 04:08 PM
SumProduct Help Sandy Excel Worksheet Functions 5 August 31st 07 03:53 PM
sumproduct? sumif(sumproduct)? David Excel Worksheet Functions 3 July 13th 07 07:06 PM


All times are GMT +1. The time now is 03:44 PM.

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"