excel - 如果 Cell.Value >(大于)函数无法为单元格着色
问题描述
我当前使用的代码。
Dim iRowCq As Range
Set iRowCq = Range("B2:DJ26")
For Each Cell In iRowCq
If Cell.Value > "0.3" or cell.value > 0.3 Then
Cell.Interior.Color = RGB(0, 255, 0)
End If
Next
我想为大于 0.3 绿色的单元格着色。然而,虽然 99% 的单元格有效,但有时有些单元格大于 0.3 并且没有着色。我什至尝试将数据四舍五入到小数点后两位,但在此之前不起作用。有人可以帮忙吗?
解决方案
您不能像这样组合字符串和数字比较来进行大于/小于比较。字符串可能不会大于"0.3"
字符串,但它的排序总是高于0.3
数字。` 组合字符串和数字比较可能在严格等于的基础上工作。
取一个字符串或一个混合数字的数值并将其用于比较。
Dim iRowCq As Range Set iRowCq = Range("B2:DJ26")
For Each Cell In iRowCq
If val(Cell.Value) > 0.3 Then
Cell.Interior.Color = RGB(0, 255, 0)
End If
Next
推荐阅读
- rest - PATCH 与 POST - 增量计数器
- python - 将部分添加到现有字符串的正确方法是什么
- r - 基于原始和特定行的新值重新排名
- php - 如何从数据库中获取数据并在 PHP 中发送响应?
- javascript - jQuery 浮点图表使用 webpack 生成“Uncaught TypeError: e.setTimeout is not a function”
- django - 如何在 Django 表单中显示标记而不是纯文本?
- mysql - MySQL 如何处理多语句?在后端同时执行?
- android - 科特林。没有返回值的函数的空返回
- php - PHP Mysql Ajax - 动态下拉菜单不起作用
- javascript - 在 PHP 或 Javascript 中将 ASCII 字符转换为 HTML 数字代码