【发布时间】:2023-03-14 01:15:01
【问题描述】:
我在 Stackoverflow 上找到了这段代码 VBA (highlight Hardcode cell (i.e.1234) in Excel) after model is built
Public Sub hightlightNoFormulas()
Dim yourRange as Range, rangeNoFormula as Range
Set yourRange = Range("A1:A100")
Set rangeNoFormula = yourRange.SpecialCells xlCellTypeFormulas
Then loop through your range, excluding any values that have formulas
Dim rng as Range
For Each rng in yourRange
If Intersect(rng,rangeNoFormula) Is Nothing Then
rng.interior.Color = 65535
End If
Next rng
Exit Sub
虽然 "Set rangeNoFormula = yourRange.SpecialCells xlCellTypeFormulas" 部分在 Excel 2010 中出现错误。我一直在寻找代码来突出显示可选范围内的单元格,这些单元格是“硬编码”而不是公式派生的(即单元格公式输入过多)。有人可以提供帮助吗?谢谢。
【问题讨论】:
-
如果你把~xlCellTypeFormulas~改成~xlCellTypeAllFormatConditions.~或者~xlCellTypeSameFormatConditions.~对你有帮助吗。
-
如果您使用 google vba specialcells 查看第一个响应,它会告诉您语法错误。
yourrange.specialcells(xlCellTypeFormulas)
标签: vba excel highlighting