Refreshing a Worksheet to Calculate a Formula

JRega

New Member
Joined
Feb 11, 2017
Messages
12
Hello,

I have a function to highlight cells in the spreadsheet that have a specific value and then count the total number for cell that are highlighted by using the formula: =CountColorIf(cell number with the color to match, range of cells to check).

When I run the function, the cells highlight correctly but the total number of highlighted cells does not display. If will only display if I copy and paste the CountColor formula into it's current cell. The copy\paste seems to "refresh" the cell and then it will display the formula. I have tried using Worksheet(worksheet name).Calculate but this does not seem to work. Any suggestions?

Thanks,
Jenifer
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi Jenifer,

May be, after pasting in current cell, it gets the color code in the formula syntax.
Can you share the code of custom formula here ?

Regards,
DILIPandey
 
Upvote 0
Here is the code I am using:

=CountColorIf($P$1,I3:N3)

Cell P1 contains the background color to match. Cells "I3:N3" refer to the cells I want checked to see if they have the color.

If I change the color of one the cells in the range I3:N3 (from not highlighted to highlighted), the formula does not update to reflect the count correctly. It will do this only if I copy/paste the formula into the same cell. This seems to refresh the formula and it displays the correct number.
 
Upvote 0
Hi JRega, I was expecting the code for the function CountColorIf. Can you share that ? thanks.


Regards,
DILIPandey
 
Upvote 0
Sorry about that. I thought it was built in.

I just did a Google and found the code:

Function CountColorIf(rSample As Range, rArea As Range) As Long
Dim rAreaCell As Range
Dim lMatchColor As Long
Dim lCounter As Long

lMatchColor = rSample.Interior.Color
For Each rAreaCell In rArea
If rAreaCell.Interior.Color = lMatchColor Then
lCounter = lCounter + 1
End If
Next rAreaCell
CountColorIf = lCounter
End Function
 
Upvote 0
Hi JRega,

Not sure if that code is in use or some other code in the function CountColorIf

Press Alt + F11 to come to VB Editor window and there you can find this code in your workbook / worksheets.


Regards,
DILIPandey
 
Upvote 0

Forum statistics

Threads
1,223,106
Messages
6,170,129
Members
452,304
Latest member
Thelingly95

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