Sum color

Sanussha

New Member
Joined
Oct 26, 2021
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
  3. Web
I have sum color function in my macro file in separately INEOS PO Calculation Template.xlsm.

I would like to use that function in all open workbook.

How do i enable sum color function in all open workbook please?

Code:

Option Explicit

Function SumColor(MatchColor As Range, sumRange As Range) As Double

Dim cell As Range
Dim myColor As Long
myColor = MatchColor.Cells(1, 1).Interior.Color

For Each cell In sumRange
If cell.Interior.Color = myColor Then
SumColor = SumColor + cell.Value
End If
Next cell
End Function


Second code:

*Also added on the workbook for any cell changes for below code:*


Code:
Private Sub Workbook_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("A:ZZ")) Is Nothing Then

End If

ActiveWorkbook.Calculate

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
This should work in any open workbook provided the workbook your function is in is also open. You have to qualify the workbook the function is in as shown below:
Try running this after you change the ranges to suit.
VBA Code:
Sub test()
Dim x
With ActiveSheet
x = Evaluate("'INEOS PO Calculation Template.xlsm'!SumColor(" & .Range("A1:A7").Address & "," & .Range("A1:A7").Address & ")")
MsgBox x
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,880
Messages
6,127,519
Members
449,385
Latest member
KMGLarson

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