Excel值不更新 [英] Excel values not updating

查看:115
本文介绍了Excel值不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VBA中做了一个功能,用于根据不同的单元格计算范围内某种颜色的单元格数量。这首先运行该功能,但是当将范围中的一个单元格的颜色更改为或正在计数的颜色时,该值不会更新。如何得到它,使功能不断更新,当我改变颜色?工作簿计算设置为自动。

I've made a function in VBA for excel that counts the number of cells of a certain color in a range, based on a different cell. This works fine first running the function, however when changing the color of one of the cells in the range to or from the color being counted, the value doesn't update. How do I get it so the function continuously updates whenever I change the color? Workbook calulations are set to automatic.

Function CountColor(rSumRange As Range)

Dim rCell As Range
Dim iCol As Integer
Dim vResult

iCol = Range("P1").Interior.ColorIndex
For Each rCell In rSumRange
    If rCell.Interior.ColorIndex = iCol Then
         vResult = vResult + 1
    End If
    Next rCell

CountColor = vResult
End Function


推荐答案

更改颜色不会触发 Worksheet_Change() / code>并且不触发任何 Application.Calculate

如果您的工作簿不有太多的公式,你可以尝试这个庞大的解决方案:

If your workbook doesn't have too many formulas, you can try this bulky solution:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.Calculate
End Sub

这篇关于Excel值不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆