【发布时间】:2016-12-08 02:24:21
【问题描述】:
我正在尝试创建一个宏来划分单元格值,如果该值大于 7.5,则将单元格着色为深绿色,然后继续将后续单元格着色为深绿色,例如 2.25 将是 2 个单元格黑暗绿色和 .25 浅绿色。此外,如果要着色的单元格的颜色内容是灰色的,则继续移动活动单元格,直到它位于没有颜色的单元格上。
For Each y In rng
If Not IsEmpty(y) And y > 7.5 And y <> "" And IsNumeric(y) Then 'I am having trouble here
y.Select
With ActiveCell.Offset(0, i).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
col = y.Value / 7.5
Count = Left(col, Len(col) - InStr(1, col, "."))
For i = 1 To Count
Do While ActiveCell.Offset(0, i).TintAndShade = -0.149998474074526
i = i + 1: Count = Count + 1
Loop
ActiveCell.Offset(0, i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
Next i
Count = Right(col, Len(col) - InStr(1, col, "."))
If Count > 0 And Count < 25 Then
ActiveCell.TintAndShade = -4.99893185216834E-02
ElseIf Count > 26 And Count < 50 Then
ActiveCell.TintAndShade = 0.799981688894314
ElseIf Count > 75 And Count < 100 Then
ActiveCell.TintAndShade = 0.599993896298105
End If
Next y
End If
Next y
该宏用于显示一周的工作量,灰色单元格是周末,因此需要跳过。
【问题讨论】:
-
究竟是什么不工作?
-
If Not IsEmpty(y) And y > 7.5 And y "" And IsNumeric(y) 那么此时y大于7.5时不会点击
-
@Lowpar 你是怎么定义的?你确定它的数值大于 7.5 吗?而不是显示为 7.5 的字符串?
-
@ShaiRado 这确实是一个好问题,但是当我在具有值的单元格上运行 =isnumber 时,它返回 true,此外该列的格式设置为一般。
-
@Lowpar 请看下面我的回答