excel - 尝试查看单元格值是否 > 10% 时代码未运行
问题描述
我的代码运行良好,我没有收到错误,但它似乎没有突出显示该列。
Sub highlight()
Dim Data As Range
Dim cell As Range
Dim currentsheet As Worksheet
Set currentsheet = ActiveWorkbook.Sheets("Watchlist")
Set Data = currentsheet.Range("B2:B50")
For Each cell In Data
If cell.Value > "10%" Then
cell.Interior.ColorIndex = 5
End If
Next
End Sub
对于要突出显示值 >10% 的任何单元格。
解决方案
改变:
If cell.Value > "10%" Then
cell.Interior.ColorIndex = 5
End If
进入:
If cell.Value > 0.1 Then
cell.Interior.ColorIndex = 5
End If
像这样的比较是通过数学完成的,像你一样写“10%”是一个字符串而不是一个数字,这意味着你可以写得很好:“If cell.Value > "ThisFunWord" Then" <--- this显然毫无意义!
推荐阅读
- google-apps-script - 仅通过按钮复制值的脚本
- notifications - 为什么我的 userNotificationCenter didReceive 在被解雇时没有运行
- node.js - Angular 7 HttpClient get - 你可以访问和处理返回对象吗?
- openscad - how to import an image into openjscad
- ios - Can not add iOS bundle identifier
- ruby-on-rails - build step 0 "gcr.io/google-appengine/exec-wrapper:latest" failed: exit status 1
- java - How to check if current phones date is today or not
- excel-formula - 如何让 VLookup 为不在 Excel 2010 列表中的条目返回零?
- python - 如何从具有特定度数的节点创建 NetworkX 子图?
- javascript - 对类使用泛型类型