我一直在努力解决这个问题,但我总是做不到!
实际上,我有一个命名的单元格区域,我希望检查该区域中的每个单元格是否大于上面的单元格,并在发生这种情况时更改其内部颜色,或者如果单元格的值相同,则相应地设置颜色。要实现如下所示的结果(忽略灰线)
我遇到的问题是让这个工作,因为命名的范围在每次刷新时都会改变!所以我不能在中编码静态单元格,它们必须每次都不同!
有什么想法吗?
我什么没试过...?哈哈
if函数,单元格偏移量,你能想到的!也许我只需要提高我的编码游戏:D
Dim Col0 As Long
Dim Col1 As Long
Dim Col2 As Long
Dim Col3 As Long
Dim Col4 As Long
Dim Col5 As Long
Dim Col6 As Long
Dim Col7 As Long
c = 0
Col0 = RGB(142, 169, 219)
Col1 = RGB(213, 184, 234)
Col2 = RGB(255, 217, 102)
Col3 = RGB(169, 208, 142)
Col4 = RGB(244, 176, 132)
Col5 = RGB(180, 238, 210)
Col6 = RGB(208, 215, 145)
Col7 = RGB(167, 127, 225)
WS.Range("C9").Interior.Color = Col1
Dim tms As Range
pr = 0
pr = ActiveSheet.Range("B15", ActiveSheet.Cells(Rows.Count, "B").End(xlUp)).Count
Set tms = Application.Range("B15:B" & 14 + pr)
Dim First As Integer
Dim Last As Integer
First = 15
Last = 15 + pr - 1
Debug.Print First
Debug.Print Last
If First <> Last Then
WS.Range("B" + First).Interior.Color = Col1
Else
Cells(k, 3).Value = "Same"
End If
Set Cel1 = WS.Range("B15")
'Col0 = "14395790"
'Col1 = "15382741"
'Col2 = "6740479"
'Col3 = "9359529"
'Col4 = "8696052"
'Col5 = "13823668"
'Col6 = "9557968"
'Col7 = "14778279"
t = 0
'MsgBox pr
'tms.Interior.Color = Col1
'For Each cel In tms.Cells
'If Cel1.Value < Cel2.Value
' Cel1.Interior.Color = "Col" & c
' c = c + 1
' End If
't = t + 1
'Next cel
'On Error Resume Next
1条答案
按热度按时间cs7cruho1#
Mike,你的思路是对的,但是你没有在时间不变的情况下保持当前颜色可用于后面的行。请注意颜色数组的用法。使用数组,你可以通过数字索引(代码中的'ColorIndex')轻松访问元素。