我正在使用 Excel 的 Active Sheet 对象来循环遍历行和列。
我需要更改单元格的背景颜色,但在此行上出现应用程序定义或对象定义错误
ws.Cells(rw, 4).Interior.ColorIndex = 0
这是我正在使用的代码
Dim ws As Worksheet
Set ws = ActiveSheet
With ws
For rw = 7 To ws.Rows.Count
For col = 2 To 12
'Check the first column and if null then exit
If ws.Cells(rw, 2) = "" Then
Exit Sub
End If
'Check if article code is less than eight digits
If Len(ws.Cells(rw, 4)) < 8 Then
ws.Cells(rw, 4).Interior.ColorIndex = 3
Else
ws.Cells(rw, 4).Interior.ColorIndex = 0
End If
Next col
Next rw
End With
有什么想法吗?