【发布时间】:2015-09-17 23:37:45
【问题描述】:
你能帮我看看我的代码有什么问题吗? 我收到一个错误:应用程序定义或对象定义错误。 我想根据单元格值为单元格着色。 如果单元格值等于单元格 1 值,则单元格应为红色。 此行出错: If Cells(i, 2).Value = Cells(i - 1, 3).Value Then
谢谢
Sub colorcells()
ThisWorkbook.Worksheets("Sheet1").Activate
Range("A1").Select
Dim i As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
For i = 1 To lastrow
If Cells(i, 2).Value = Cells(i - 1, 3).Value Then
Cells(i, 1).Interior.ColorIndex = 3
End If
Next i
End Sub
【问题讨论】:
-
当
i = 1时,Cells(i - 1, 3)会出现问题,因为没有第 0 行。