为什么我会遇到VBA Typer不匹配错误?

发布于 2025-02-11 15:33:31 字数 233 浏览 1 评论 0原文

尝试在我的VBA代码中创建一个有条件的语句,以突出显示C列中的任何小于2的RED。

 Set result = Range("C:C").Value
             If result < 2 Then
                  MyRange.Font.ColorIndex = 3
             End If

不确定为什么我会遇到类型不匹配错误。

Trying to create a conditional statement in my VBA code for a pivot table to highlight red any values less than 2 in Column C.

 Set result = Range("C:C").Value
             If result < 2 Then
                  MyRange.Font.ColorIndex = 3
             End If

Not sure why I'm getting a type mismatch error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走野 2025-02-18 15:33:31

我喜欢有条件的格式选项。

否则类似的事情可能会很好地工作:

Dim rng as range
for each rng in Range("C1:C" & Range("C" & Rows.Count).End(xlup).row)
    If rng.value < 2 Then
        rng.Font.ColorIndex = 3
    End If
next rng

我还没有检查颜色的实际应用

这应该使您更加接近

I like the conditional formatting option.

otherwise something like this might work well:

Dim rng as range
for each rng in Range("C1:C" & Range("C" & Rows.Count).End(xlup).row)
    If rng.value < 2 Then
        rng.Font.ColorIndex = 3
    End If
next rng

I haven't checked the actual application of colour

this should get you a little closer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文