gpt4 book ai didi

excel - 简单代码上的 VBA 内存不足错误

转载 作者:行者123 更新时间:2023-12-04 21:58:36 26 4
gpt4 key购买 nike

我有一个非常简单的代码,我正在尝试运行,这里:

Sub Highlight()
Dim Diff As Range, cell As Range
Set Diff = Sheets(1).UsedRange.Columns("N:S")
For Each cell In Diff
If cells.Value2 > 0.1 Then
cell.Interior.ColorIndex = 0
End If
Next
End Sub

但是,就在 If 语句处,我得到运行时 7:内存不足。我在一个相当小的数据集(<5,000 个单元格)上运行它,并关闭了所有其他程序/不必要的进程,并且任务管理器显示了足够的内存。我不知道此时可能是什么原因造成的。

有任何想法吗?

最佳答案

您的代码中有错字。您的 For Each变量是 cell ,但您的代码使用 cells.Value2 .

For Each cell In Diff                 ' Using cell (singular)
If cells.Value2 > 0.1 Then ' Using cells (plural)
cell.Interior.ColorIndex = 0
End If
Next

此外,我怀疑您的范围 ( Diff ) 中的值不是数字或为空。

关于excel - 简单代码上的 VBA 内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39135263/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com