VB Function Not Recalling

UDcc123

Board Regular
Joined
Feb 24, 2004
Messages
93
I received the coding for the function below from a peer. I copy/pasted this code into Module1 in my personal.xlsb file within the VB Editor. When I try to recall the function, the cell populates with #NAME? I've tried closing & re-opening excel and that did not fix it. Any help that you can provide is greatly appreciated.


I typed: =COUNTCOLOR(H3,D3:E22)
and received: #NAME?

Function CountColor(rColor As Range, rSumRange As Range)

Dim rCell As Range
Dim iCol As Integer
Dim vResult

iCol = rColor.Interior.ColorIndex

For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
vResult = vResult + 1
End If
Next rCell

CountColor = vResult
End Function
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You need to include personal.xls or personal.xlsb depending on your version of Excel. For example

=PERSONAL.XLSB!countcolor(A1,B1:B8)

for XL 2007 and above.
 
Upvote 0
That worked...but one more question. The function is set to count the # of cells highlighted with a certain color. The issue I'm having is that when I change the colors of my lookup array, the formula won't automatically update...I need to refresh the cell with the formula in it.

Is there a way for this function in my personal.xlsb to transfer into the VB code for the file in use without going in and copy/pasting it each time? I may only use this function in 5-10% of all my files, so I wouldn't want the function copied into all excel files...just the ones where it's in use.

Thanks!
 
Last edited:
Upvote 0
To get it to automatically refresh add in the line:

Application.volatile = true

Hope that helps.
 
Upvote 0
Where do I add in the line within the function (I'm not familiar with VB...just copy/paste from code given to me)
 
Upvote 0
Here

Code:
Function CountColor(rColor As Range, rSumRange As Range)
Application.Volatile
 
Upvote 0
Thank you all so much...that worked. I still need a recalc as was mentioned, but now it will recalculate with any random cell refresh (prior to adding application.volatile, I needed to refresh every cell with the formula).
 
Upvote 0

Forum statistics

Threads
1,222,643
Messages
6,167,268
Members
452,108
Latest member
Sabat01

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