使用如下VBA代码取得相应的单元格底色
Sub SetTo60()
'
Dim oStr As String '获取当前计算单元格的内容
Dim oSel As Range '定义当前计算的区域(单元格)
Dim oSng As Single '获取当前计算机单元格的单精度值
For Each oSel In Selection
oStr = Cells(oSel.Row, oSel.Column).Value
If oStr <> "" Then '空单元格直接不操作,进入下层循环
If IsNumeric(oStr) Then '不能转换为数值类型时跳过,进入下层循环
oSng = CSng(oStr)
If oSng > -1 And oSng < 1 Then '如果小于60则填充为60
If oSng <> 0 Then '如果等于0则跳过,进入下层循环
'Cells(oSel.Row, oSel.Column).Value = 8888
oSel.Interior.ColorIndex = 10 '对应的色谱如下所示。
End If
End If
End If
End If
Next oSel
End Sub
| 无色 | 0 | 19 | 38 | ||
| 1 | 20 | 39 | |||
| 白色 | 2 | 21 | 40 | ||
| 3 | 22 | 41 | |||
| 4 | 23 | 42 | |||
| 5 | 24 | 43 | |||
| 6 | 25 | 44 | |||
| 7 | 26 | 45 | |||
| 8 | 27 | 46 | |||
| 9 | 28 | 47 | |||
| 10 | 29 | 48 | |||
| 11 | 30 | 49 | |||
| 12 | 31 | 50 | |||
| 13 | 32 | 51 | |||
| 14 | 33 | 52 | |||
| 15 | 34 | 53 | |||
| 16 | 35 | 54 | |||
| 17 | 36 | 55 | |||
| 18 | 37 | 56 |
2万+

被折叠的 条评论
为什么被折叠?



