Skip to content
本页内容

HasFormula (属性)

如果区域中所有单元格均包含公式,则该属性值为 True;如果所有单元格均不包含公式,则该属性值为 False;其他情况下为 NoneAny 类型,只读。

示例

python
#本示例提示用户选定 sheet1 的区域。如果该选定区域内所有单元格均包含公式,则本示例将显示消息框
def test():
    Worksheets.Item("Sheet1").Activate()
    rr = Application.InputBox("Select a range on this worksheet", None, None, None, None, None, None, 8)
    if rr.HasFormula:
        print("Every cell in the selection contains a formula")
python
#本示例检查 B1:C1 单元格区域是否所有单元格都含有公式,然后给他们分别设置公式,查看结果
def test():
    print(Range("B1:C1").HasFormula) #False
    Range("B1").Formula = "=B2+B3"
    print(Range("B1:C1").HasFormula) #None
    Range("C1").Formula = "=C2+C3"
    print(Range("B1:C1").HasFormula) #True