Excel用VBA把这个DO循环改为FOR循环

Excel用VBA把这个DO循环改为FOR循环
2025-03-20 21:53:04
推荐回答(4个)
回答1:

Sub test()
    Dim i%, c%
    For i = 26 To 10 Step -1
        If Cells(i, 7) = Cells(28, 6) Then
            c = c + 1
        End If
    Next
    [G28] = c
End Sub

回答2:

for i=10 to 26
If cells(i,6)=cells(28,6) then
c=c+1
End if
Next

回答3:

for i=26 to 1 step -1
if cells(i,7)=cells(28,6) then exit for
next
[g28]=26-i

回答4:

Sub 结果输出()
Dim i As Integer, c As Integer
For i = 26 To 10 Step -1
c = c + 1
If Cells(i, 7) <> Cells(28, 6) Then Exit For
Next
MsgBox c - 1
End Sub