excel vba 多for循环和多条件问题? EXCEL的VBA多重循环问题?

excel vba \u591afor\u5faa\u73af\u548c\u591a\u6761\u4ef6\u95ee\u9898\uff1f

\u601d\u8def\uff1a\u7b5b\u9009\u540e\u8bb0\u5f55\u6bcf\u884c\u6765\u81ea\u4e8e\u54ea\u4e2a\u5de5\u4f5c\u8868\u54ea\u4e00\u884c\uff0c\u4fdd\u5b58\u65f6\u628a\u503c\u518d\u590d\u5236\u56de\u53bb\uff0c\u4e0d\u96be\u7684

if endif\u6570\u91cf\u4e0d\u5339\u914d\uff0c\u5f53\u6ca1\u6709endif\u65f6\uff0cif\u5fc5\u987b\u5199\u5728\u540c\u4e00\u884c\uff0cexit do\u8fd9\u4e2a\u4f4d\u7f6e\u548cloop\u4e00\u8d77\u662f\u5565\u610f\u601d\u5462

Sub Macro2()
Dim A%
A = 1
Do While A < 10

If Cells(A, 1).Value = "\u5c3a\u5bf8" And Cells(A + 1, 1).Value = "" Then Cells(A + 2, 1) = "S"

If Cells(A, 1).Value = "\u5c3a\u5bf8" And Cells(A + 2, 1).Value = "" Then Cells(A + 2, 1) = "M"

If Cells(A, 1).Value = "\u5c3a\u5bf8" And Cells(A + 1, 1).Value = "\u6e29\u99a8\u63d0\u793a" Then
Cells(A + 1, 1) = "\u5747\u7801"
End If
Loop
End Sub

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
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

扩展阅读:java ... vba编程必背50个程序 ... python vba ... excel home ... microsoft visio ... vba入门 ... vba case ... excel vba if ... vba快捷打开 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网