我试图根据关键字在2500行表格中填充单元格。有10个关键字和3种不同的颜色,我需要。我想出了以下,但我得到“运行时错误'13':类型不匹配”。恐怕我不知道那是什么。VBA基于单元格文本填充颜色
Sub ColourChange()
Dim cell As Range
For Each cell In Range("a2:az500")
If cell.Value = "Available" Then
cell.Interior.Color = XlRgbColor.rgbLightGreen
ElseIf cell.Value = "Deal" Then
cell.Interior.Color = XlRgbColor.rgbRed
ElseIf cell.Value = "Sold +Excl" Then
cell.Interior.Color = XlRgbColor.rgbRed
ElseIf cell.Value = "Sold Excl" Then
cell.Interior.Color = XlRgbColor.rgbRed
ElseIf cell.Value = "Holdback" Then
cell.Interior.Color = XlRgbColor.rgbRed
ElseIf cell.Value = "Pending" Then
cell.Interior.Color = XlRgbColor.rgbRed
ElseIf cell.Value = "Expired" Then
cell.Interior.Color = XlRgbColor.rgbRed
ElseIf cell.Value = "Sold CoX" Then
cell.Interior.Color = XlRgbColor.rgbRed
ElseIf cell.Value = "Resell" Then
cell.Interior.Color = XlRgbColor.rgbLightGreen
ElseIf cell.Value = "Sold nonX" Then
cell.Interior.Color = XlRgbColor.rgbBlue
ElseIf cell.Value = "Sold NonX" Then
cell.Interior.Color = XlRgbColor.rgbBlue
End If
Next
End Sub
谢谢!结束如果之前
Else
debug.print cell.value & cell.address
:
Ĵ
,如果你有在小区中的错误可能发生。检查内容是否中断。 – SJR
雅,它没有明显的原因退出237行? –
为什么不使用条件格式,因为你的范围是硬编码的?此外,如果不满足这些条件,您应该使用Case Select和其他选项。 – mooseman