VBAexit退出循环和函数
VBA退出循环⽤Exit语句,在循环中使⽤Exit语句相当于C/C++的break语句,⽽在函数中使⽤Exit语句则相当于C/C++的return语句。
⼀、退出循环。exit for退出for循环,exit do⽤于退出do 或 do while循环:
'获取⾮空⾏
Function GetNotNullRow(ByVal iStartRow, ByRef iRow)
Dim Rng As Range
For Each Rng In Range("B" & iStartRow & ":" & "P" & 100)
If Rng <> "" Then
iRow = Rng.Row
Exit For
End If
Next
End Function
⼆、退出函数。exit sub退出过程,exit function 退出function:
'获取源⼯作簿名
Sub GetSourceWorkbookName(strPath As String)
Dim strName As String
Dim iCount As Integer
iCount = 0
strName = Dir(strPath & "*.xls*")
exit是什么意思英语While Len(strName) > 0
If strName <> strMainWorkbookName Then
ReDim Preserve arrSourceWorkbookName(iCount)
arrSourceWorkbookName(iCount) = strName
strName = Dir()
iCount = iCount + 1
Else
Exit Sub
End If
Wend
End Sub
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论