|
我的代码如下,注释掉ELSE 和 END IF中的代码,就不会报错。不注释,就会报“下标越界”。特别不解这是为什么呢?
Option Explicit
Option Base 1
Sub wbcheck()
'根据sheet("中信")中的B列去匹配sheet("DG")的C列,如果相同,则在相应的单元格上填充颜色
Dim i As Integer, str As Variant, j As Integer, STR2 As Variant, am As String
For j = 19 To 45 Step 1 'sheet("中信")中,想要比较的数据是从19行开始,到45行结束
For i = 6 To 1300 Step 1 'sheet("DG")中,想要比较的数据是从6行开始,到1300行结束
str = Right(Sheets("DG").Range("C" & i).Value, 6)
STR2 = Sheets("中信").Range("B" & j).Value
am = Sheets("DG").Range("AM" & i).Value
If (STR2 = str) And (am <> "0") Then
Sheets("中信").Cells(j, "B").Interior.ColorIndex = 5
Sheets("DG").Cells(i, "C").Interior.ColorIndex = 10
Else
Sheets("中信").Cells(j, "B").Interior.ColorIndex = 50
Sheets("DG").Cells(i, "C").Interior.ColorIndex = 100
End If
Next i
Next j
End Sub
该贴已经同步到 王小博vba的微博 |
|