VBA not auto updating cell values

Chrispykill

New Member
Joined
Aug 11, 2017
Messages
2
Hi,

I am using a VBA to count cells based on their fill colour. I am using the following script:

Function CountColor(Rng As Range, RngColor As Range) As Integer
Application.Volatile True
Dim Cll As Range
Dim Clr As Long
Clr = RngColor.Range("A1").Interior.Color
For Each Cll In Rng
If Cll.Interior.Color = Clr Then
CountColor = CountColor + 1
End If
Next Cll
End Function

Then in the cell I am using this formula:

=countcolor(B7:Q7,W7)

Where B7:Q7 is the range and W7 the referenced colour.

When changing a cell in the range to the reference colour the only way to get the count value to update is if I double click the cell and press ENTER.

I did have the script without the volatile, with the volatile, and then with the volatile and TRUE at the end. Neither of these worked in auto updating.

Can someone please help?

Thanks!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
There is something that I don't understand and might be a problem.

If you use a 1 cell range for RngColor, why aren't you simply doing this.

Code:
Clr=RngColor.interior.Color
 
Upvote 0
Change that line
Code:
[COLOR=#333333]Clr = RngColor.Range("A1").Interior.Color[/COLOR]

For this
Code:
Clr=RngColor.interior.Color

After reading your problem again, it seems that your Excel doesn't automatically recalculate formula.
To activate that, you can go in Options-> Formula and select Automatic of Workbook calculation
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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