|
楼主 |
发表于 2015-5-31 21:33
|
显示全部楼层
scl5801 发表于 2015-5-31 21:12
现在不包括r列,你把r列的颜色去掉即可,r列是我测试时多选了一列。
这个我知道了。谢谢!我把您给的代码经过修改了一下才是我最想要的结果。代码如下面最后。
但是,现在问题又来了:
1,为什么您没有把代码放在模块里面,而是直接放在了表里,这样也可以?我从来没有这样用过。而且,您的代码是以Pubic开头,而不是直接以Sub开始?
2,要怎么样才能让它自动运行呢?不可能给它个按钮,每次都要来按一次吧?
3,因为表里我用的都是公式,最终显示的%结果格式是不保留小数位的,所以有时的100%并不是真正的100%而可能是99.99%,所以它就会被认为是<100%,怎样来解决这个问题呢?
再次谢谢您!
Public Sub 填色()
Dim i%
With Application
.ScreenUpdating = False
For i = 1 To 15
If .Cells(6, i + 2) > 2 And .Cells(6, i + 2) <> "" Then
.Cells(6, i + 2).Interior.ColorIndex = 3
.Cells(6, i + 2).Font.ColorIndex = 2
Else
.Cells(6, i + 2).Interior.Color = RGB(0, 255, 0)
End If
If .Cells(7, i + 2) < 1 And .Cells(7, i + 2) <> "" Then
.Cells(7, i + 2).Interior.ColorIndex = 3
.Cells(7, i + 2).Font.ColorIndex = 2
Else
.Cells(7, i + 2).Interior.Color = RGB(0, 255, 0)
End If
If .Cells(13, i + 2) > 2 And .Cells(13, i + 2) <> "" Then
.Cells(13, i + 2).Interior.ColorIndex = 3
.Cells(13, i + 2).Font.ColorIndex = 2
Else
.Cells(13, i + 2).Interior.Color = RGB(0, 255, 0)
End If
If .Cells(14, i + 2) < 1 And .Cells(14, i + 2) <> "" Then
.Cells(14, i + 2).Interior.ColorIndex = 3
.Cells(14, i + 2).Font.ColorIndex = 2
Else
.Cells(14, i + 2).Interior.Color = RGB(0, 255, 0)
End If
If .Cells(20, i + 2) > 6 And .Cells(20, i + 2) <> "" Then
.Cells(20, i + 2).Interior.ColorIndex = 3
.Cells(20, i + 2).Font.ColorIndex = 2
Else
.Cells(20, i + 2).Interior.Color = RGB(0, 255, 0)
End If
If .Cells(21, i + 2) < 1 And .Cells(21, i + 2) <> "" Then
.Cells(21, i + 2).Interior.ColorIndex = 3
.Cells(21, i + 2).Font.ColorIndex = 2
Else
.Cells(21, i + 2).Interior.Color = RGB(0, 255, 0)
End If
For r = 0 To 3
If .Cells(27 + r * 7, i + 2) > 4 And .Cells(27 + r * 7, i + 2) <> "" Then
.Cells(27 + r * 7, i + 2).Interior.ColorIndex = 3
.Cells(27 + r * 7, i + 2).Font.ColorIndex = 2
Else
.Cells(27 + r * 7, i + 2).Interior.Color = RGB(0, 255, 0)
End If
If .Cells(28 + r * 7, i + 2) < 1 And .Cells(28 + r * 7, i + 2) <> "" Then
.Cells(28 + r * 7, i + 2).Interior.ColorIndex = 3
.Cells(28 + r * 7, i + 2).Font.ColorIndex = 2
Else
.Cells(28 + r * 7, i + 2).Interior.Color = RGB(0, 255, 0)
End If
Next r
Next i
End With
End Sub
|
|