您好我最近问的问题,在这里: Assigning Colours to each Instance of a value, 然而,这结束了工作不适合我,我不确定我是否应该在继续该线程或开始一个新的,因为我已经改变了一些东西。这里是我的新代码,它交替选择两列之间的单元格并更改所选单元格的颜色,但是如果数字已经存在,我希望它们具有相同的颜色。我现在拥有的东西似乎并不匹配,并且尽管存在匹配,仍会指定随机颜色。值的每个实例都得到相同的颜色和新的价值观得到了新的色彩
Sub colourNumbers()
Dim a As Long
Dim b As Long
Set wf = Application.WorksheetFunction
Dim analysisSheet As Worksheet
Set analysisSheet = ActiveSheet
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For a = 3 To lastRow
If b = 3 Then
b = 5
Else
b = 3
End If
If b = 5 Then
a = a - 1
End If
analysisSheet.Cells(a, b).Select
With Selection
x = 0
On Error Resume Next
x = wf.Match(Selection.Value, _
Range("C3:E" & [C3000].End(xlUp).Row), 0)
On Error GoTo 0
If x > 0 Then
target.Interior.Color = Cells(x, 3).Interior.Color
Else
Selection.Interior.Color = RGB(_
wf.RandBetween(125, 255), wf.RandBetween(125, 255), wf.RandBetween(125, 255))
End If
End With
Next a
End Sub
任何帮助,将不胜感激!
匹配函数将单个列的范围作为查找数组......所以在你的情况下它本身会抛出错误的编译时间,但是由于你添加了忽略错误语句,你无法看到它。 所以,你只是改变col C和E的颜色,所以我猜你想要在这两个col自身中搜索关键字...... –