VBA 学习

Sub MyTest()
'A 列?B列的演示
    Dim i As Long
    
    i = 1
    While True
        If i > 10 Then GoTo ENDLOOP
        
        Cells(i, 1) = 1
        
        If i Mod 2 = 0 Then GoTo Nextloop1
        Cells(i, 2) = i * i
        
Nextloop1:
    i = i + 1
    Wend
    
ENDLOOP:

'在C列、D列的演示
    For i = 1 To 10000
        If i > 10 Then Exit For '或 if i > 10 then exit sub
        
        Cells(i, 3) = i
        If i Mod 2 = 0 Then GoTo nextloop2 '中断当前循环
        Cells(i, 4) = i * i
        
nextloop2:
    Next
End Sub

猜你喜欢

转载自www.cnblogs.com/ckstock/p/11788308.html
vba
今日推荐