excel vba 多for循环和多条件问题?
DimaimAsWorksheetSetaim=Sheets("REDatabase")DimiAsIntegerDimjAsIntegerIfM_type.Text="...
Dim aim As Worksheet
Set aim = Sheets("RE Database")
Dim i As Integer
Dim j As Integer
If M_type.Text = "" Then
Exit Sub
Else
For i = 3 To 200
If Me.M_level1.Text = aim.Cells(5, i) Then
For j = 5 To 100
If aim.Cells(j, i) <> "" Then
Me.M_level1.AddItem aim.Cells(j, i)
Else
Exit For
End If
Next j
Exit For
Else
Next i
End If
end if
第一个循环判断等式是否成立,如果成立执行第二个循环,执行完后退出循环,如果不成立继续第一循环直到成立为止。但是总是提示错误 next without for,请高手指点一下,谢谢! 展开
Set aim = Sheets("RE Database")
Dim i As Integer
Dim j As Integer
If M_type.Text = "" Then
Exit Sub
Else
For i = 3 To 200
If Me.M_level1.Text = aim.Cells(5, i) Then
For j = 5 To 100
If aim.Cells(j, i) <> "" Then
Me.M_level1.AddItem aim.Cells(j, i)
Else
Exit For
End If
Next j
Exit For
Else
Next i
End If
end if
第一个循环判断等式是否成立,如果成立执行第二个循环,执行完后退出循环,如果不成立继续第一循环直到成立为止。但是总是提示错误 next without for,请高手指点一下,谢谢! 展开
3个回答
展开全部
NEXT I之后的END IF应该放在NEXT I之前,另外EXIT SUB的IF我取消了ELSE和END IF,因为满足条件时肯定不执行后面的代码了,由于我在SUB里面编译,自己定义了一个Mee代替你的Me,目前编译没有问题,逻辑估计是你需要的:
Dim aim As Worksheet, Mee
Set aim = Sheets("RE Database")
Dim i As Integer
Dim j As Integer
If M_type.Text = "" Then Exit Sub
For i = 3 To 200
If Mee.M_level1.Text = aim.Cells(5, i) Then
For j = 5 To 100
If aim.Cells(j, i) <> "" Then
Mee.M_level1.AddItem aim.Cells(j, i)
Else
Exit For
End If
Next j
Exit For
Else
End If
Next i
Dim aim As Worksheet, Mee
Set aim = Sheets("RE Database")
Dim i As Integer
Dim j As Integer
If M_type.Text = "" Then Exit Sub
For i = 3 To 200
If Mee.M_level1.Text = aim.Cells(5, i) Then
For j = 5 To 100
If aim.Cells(j, i) <> "" Then
Mee.M_level1.AddItem aim.Cells(j, i)
Else
Exit For
End If
Next j
Exit For
Else
End If
Next i
展开全部
Dim aim As Worksheet
Set aim = Sheets("RE Database")
Dim i As Integer
Dim j As Integer
If M_type.Text = "" Then
Exit Sub
Else
For i = 3 To 200
If Me.M_level1.Text = aim.Cells(5, i) Then
For j = 5 To 100
If aim.Cells(j, i) <> "" Then
Me.M_level1.AddItem aim.Cells(j, i)
Else
Exit For
End If
Next j
Exit For
Else
goto 100
End If
100:
Next i
end if
Set aim = Sheets("RE Database")
Dim i As Integer
Dim j As Integer
If M_type.Text = "" Then
Exit Sub
Else
For i = 3 To 200
If Me.M_level1.Text = aim.Cells(5, i) Then
For j = 5 To 100
If aim.Cells(j, i) <> "" Then
Me.M_level1.AddItem aim.Cells(j, i)
Else
Exit For
End If
Next j
Exit For
Else
goto 100
End If
100:
Next i
end if
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
For j = 5 To 100
If aim.Cells(j, i) <> "" Then
Me.M_level1.AddItem aim.Cells(j, i)
Else
Exit For
End If
Next j
End If
Next i
End If
End If
If aim.Cells(j, i) <> "" Then
Me.M_level1.AddItem aim.Cells(j, i)
Else
Exit For
End If
Next j
End If
Next i
End If
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询