excel vba 多for循环和多条件问题?
答案:3 悬赏:10 手机版
解决时间 2021-03-17 05:28
- 提问者网友:战魂
- 2021-03-16 15:57
excel vba 多for循环和多条件问题?
最佳答案
- 五星知识达人网友:雾月
- 2021-03-16 16:38
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
全部回答
- 1楼网友:你哪知我潦倒为你
- 2021-03-16 17:58
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
- 2楼网友:从此江山别
- 2021-03-16 17:25
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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯