【问题标题】:Run-Time error '438' "Object doesn't support this property or method"运行时错误“438”“对象不支持此属性或方法”
【发布时间】:2016-03-07 20:29:23
【问题描述】:

我收到“438”错误,当我调试时,以下行以黄色突出显示

If (Sheet4.Cells(i, j).ColorIndex <> xlNone) Then

我找不到出现此错误的原因。是语法错误吗?还是更大的问题?我需要在我的代码中多次查看或更改单元格的颜色。 有什么想法吗?

【问题讨论】:

    标签: vba excel runtime-error


    【解决方案1】:

    Range.Cells property 没有 .ColorIndex 属性。但是,它的 .Interior 或可能的 .Font 可以有一个 .ColorIndex。要检查单元格的填充是否有颜色,您可以对照 xlNone 检查 .Pattern。

    'for Fill
    If Sheet4.Cells(i, j).Interior.Pattern <> xlNone Then
    'for Font
    If Sheet4.Cells(i, j).Font.ColorIndex <> xlAutomatic Then
    

    对照 xlColorIndexAutomatic 检查字体颜色索引可能是更好的方法。您的问题缺乏一些细节。

    【讨论】:

    • 感谢@Jeeped 解决了这个问题。语法错误感谢上帝。 :)
    猜你喜欢
    • 1970-01-01
    • 2014-03-21
    • 2023-03-30
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多