VBA一直显示下标越界,怎么改写? 10
Subtest()Dimi,j,m,nAsIntegerSetD1=Workbooks("A1.xlsm").Worksheets("Sheet1")SetD2=Work...
Sub test()
Dim i, j, m, n As Integer
Set D1 = Workbooks("A1.xlsm").Worksheets("Sheet1")
Set D2 = Workbooks("A2.xlsm").Worksheets("Sheet1")
For i = 3 To 3049
For j = 3 To 101
If D2.Cells(i, 4) = D1.Cells(j, 4) And D2.Cells(i, 8) = D1.Cells(j, 8) Then
D2.Cells(i, 4).Interior.Color = RGB(255, 255, 0)
End If
Next j
Next i
For m = 3 To 3049
For n = 3 To 101
If D2.Cells(m, 4).Interior.Color = RGB(255, 255, 0) Then
GoTo line1
End If
If D2.Cells(m, 4) = D1.Cells(n, 4) And D2.Cells(m, 8) <> D1.Cells(n, 8) Then
D2.Cells(m, 4).Interior.Color = RGB(255, 0, 0)
GoTo line1
End If
Next n
line1:
Next m
End Sub
两张表里面同时对比两项数据,但是每次运行都显示
Set D1 = Workbooks("A1.xlsm").Worksheets("Sheet1")
Set D2 = Workbooks("A2.xlsm").Worksheets("Sheet1")这段下标越界,请问怎么去更改? 展开
Dim i, j, m, n As Integer
Set D1 = Workbooks("A1.xlsm").Worksheets("Sheet1")
Set D2 = Workbooks("A2.xlsm").Worksheets("Sheet1")
For i = 3 To 3049
For j = 3 To 101
If D2.Cells(i, 4) = D1.Cells(j, 4) And D2.Cells(i, 8) = D1.Cells(j, 8) Then
D2.Cells(i, 4).Interior.Color = RGB(255, 255, 0)
End If
Next j
Next i
For m = 3 To 3049
For n = 3 To 101
If D2.Cells(m, 4).Interior.Color = RGB(255, 255, 0) Then
GoTo line1
End If
If D2.Cells(m, 4) = D1.Cells(n, 4) And D2.Cells(m, 8) <> D1.Cells(n, 8) Then
D2.Cells(m, 4).Interior.Color = RGB(255, 0, 0)
GoTo line1
End If
Next n
line1:
Next m
End Sub
两张表里面同时对比两项数据,但是每次运行都显示
Set D1 = Workbooks("A1.xlsm").Worksheets("Sheet1")
Set D2 = Workbooks("A2.xlsm").Worksheets("Sheet1")这段下标越界,请问怎么去更改? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询