Excel VBA下标越界
PrivateSubWorksheet_SelectionChange(ByValTargetAsRange)DimnumAsLongnum=Worksheets(5)....
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim num As Long
num = Worksheets(5).Cells(Rows.Count, 1).End(xlUp).Row - 1
For i = 5 To num
If Worksheets(5).Cells(i, 5).Value <> "" Then
Worksheets(5).Cells(i, 4).Value = Evaluate("VLookup(" & Chr(34) & Worksheets(5).Cells(i, 5).Value & Chr(34) & ", 参数!$A:$B, 2, False)")
End If
If Worksheets(5).Cells(i, 9).Value <> "" Then
Worksheets(5).Cells(i, 8).Value = Evaluate("VLookup(" & Chr(34) & Worksheets(5).Cells(i, 9).Value & Chr(34) & ", 参数!$N$4:$O$10, 2, False)")
Worksheets(5).Cells(i, 7).Value = 0
End If
If Worksheets(5).Cells(i, 11).Value <> "" Then
Worksheets(5).Cells(i, 10).Value = Evaluate("VLookup(" & Chr(34) & Worksheets(5).Cells(i, 11).Value & Chr(34) & ", 参数!$K$4:$L$65, 2, False)")
End If
Next i
End Sub
运行的时候总是提示下标越界,然后第三句代码标黄num = Worksheets(5).Cells(Rows.Count, 1).End(xlUp).Row - 1。。。这是为什么呢?本人vba新手,还烦请详细些~ 展开
Dim num As Long
num = Worksheets(5).Cells(Rows.Count, 1).End(xlUp).Row - 1
For i = 5 To num
If Worksheets(5).Cells(i, 5).Value <> "" Then
Worksheets(5).Cells(i, 4).Value = Evaluate("VLookup(" & Chr(34) & Worksheets(5).Cells(i, 5).Value & Chr(34) & ", 参数!$A:$B, 2, False)")
End If
If Worksheets(5).Cells(i, 9).Value <> "" Then
Worksheets(5).Cells(i, 8).Value = Evaluate("VLookup(" & Chr(34) & Worksheets(5).Cells(i, 9).Value & Chr(34) & ", 参数!$N$4:$O$10, 2, False)")
Worksheets(5).Cells(i, 7).Value = 0
End If
If Worksheets(5).Cells(i, 11).Value <> "" Then
Worksheets(5).Cells(i, 10).Value = Evaluate("VLookup(" & Chr(34) & Worksheets(5).Cells(i, 11).Value & Chr(34) & ", 参数!$K$4:$L$65, 2, False)")
End If
Next i
End Sub
运行的时候总是提示下标越界,然后第三句代码标黄num = Worksheets(5).Cells(Rows.Count, 1).End(xlUp).Row - 1。。。这是为什么呢?本人vba新手,还烦请详细些~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询