sumbycolor has stopped working

EddieL

New Member
Joined
Jan 20, 2019
Messages
5
Hi All

I had this procedure working perfectly but it suddenly stopped and is not recognising CL as a variable. I have highlighted the CL in blue which is what excel does when it shows "Expected Function or Variable". Could anyone help please? I have remmed out col1 = CL.Interior.ColorIndex as I could not see it having any value in this code.

Function SumByColor(CellColor As Range, rRange As Range)
'Stop
Dim cSum As Long
Dim ColIndex As Integer
ColIndex = CellColor.Interior.ColorIndex
For Each CL In rRange
'col1 = CL.Interior.ColorIndex
If CL.Interior.ColorIndex = ColIndex Then
If CL = "AL7.5" Then ct = 7.5
If CL = "AL12.5" Then ct = 12.5
If CL = "ST" Then ct = 7.5
If CL = "SK7.5" Then ct = 7.5
If CL = "SK12.5" Then ct = 12.5
If CL = "CL7.5" Then ct = 7.5
If CL = "CL12.5" Then ct = 12.5
If CL = "CL13.5" Then ct = 13.5
If CL = "M7.5" Then ct = 7.5
If CL = "M12.5" Then ct = 12.5
If CL = "M13.5" Then ct = 13.5
cSum = WorksheetFunction.Sum(ct, cSum)
End If
Next CL
SumByColor = cSum
End Function
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi & welcome to MrExcel.
Add this to your declarations
Code:
Dim Cl as Range
 
Upvote 0
Hi Fluff

Thank you so much. I thought I had tried that, but after adding it I now have it working perfectly again.

Thanks once again.

EddieL
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,938
Members
449,197
Latest member
k_bs

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