excel vba 下标越界问题,如何解决?
Subtj()'定义tj()Dimbm()'定义数组表名bm()i=Worksheets.Count'i=表的张数ReDimbm(1Toi)'重新定义数组表名(1toi)...
Sub tj() '定义tj()
Dim bm() '定义数组表名bm()
i = Worksheets.Count 'i=表的张数
ReDim bm(1 To i) '重新定义数组表名(1 to i)
For x = 2 To i '循环 从2到i
bm(x) = Sheets(x).Name '把表的名字给 表名()
Next
For y = 4 To 80
For z = 1 To i
If Cells(y, 3) = bm(z) Then
If Sheets(bm(z)).Cells(34, 8) = "借" Then '(就是这个地方说是下标越界)
Cells(y, 2) = Sheets(bm(z)).Cells(34, 9) * (-1)
ElseIf Sheets(bm(z)).Cells(34, 8) = "贷" Then
Cells(y, 2) = Sheets(bm(z)).Cells(34, 9) * (-1)
End If
End If
Next
Next 展开
Dim bm() '定义数组表名bm()
i = Worksheets.Count 'i=表的张数
ReDim bm(1 To i) '重新定义数组表名(1 to i)
For x = 2 To i '循环 从2到i
bm(x) = Sheets(x).Name '把表的名字给 表名()
Next
For y = 4 To 80
For z = 1 To i
If Cells(y, 3) = bm(z) Then
If Sheets(bm(z)).Cells(34, 8) = "借" Then '(就是这个地方说是下标越界)
Cells(y, 2) = Sheets(bm(z)).Cells(34, 9) * (-1)
ElseIf Sheets(bm(z)).Cells(34, 8) = "贷" Then
Cells(y, 2) = Sheets(bm(z)).Cells(34, 9) * (-1)
End If
End If
Next
Next 展开
2个回答
展开全部
For x = 2 隐团州To i 或派 '循灶蔽环 从2到i
bm(x) = Sheets(x).Name '把表的名字给 表名()
Next
你这里是从2开始循环的,bm(1)并没有值。
For z = 1 To i
If Cells(y, 3) = bm(z) Then
If Sheets(bm(z)).Cells(34, 8) = "借" Then '(就是这个地方说是下标越界)
你这里的z是从1开始的,所以会出错
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询