Question: Copy the # 3 Excel template to your Excel file. Use the fill tool to fill the 6 cells ( H 1 through M 1

Copy the #3 Excel template to your Excel file. Use the fill tool to fill the 6 cells (H1 through M1) with the
appropriate colors. These colors are under standard colors when you open the fill tool. Create a function
called Colorfunction which takes three parameters (see the code below). First is the cell location of the color
(H1 through M1), second is the range of cell locations (A1:E20), and finally a TRUE or FALSE condition. True
being the sum, and false the count. Remember the user defined function should be saved in a module in VBA.
Fill in the cells H2:M3 using this function to determine the sum of the values with these colors, and also the
count of the number of cells with the color.
Public Function ColorFunction(rColor As Range, rRange As Range, Optional
SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
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 =2+ vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
Is the output correct? If not, please change the code accordingly to create a correct output.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!