全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 Excel
1124 1
2013-12-30
From the following code, since it will create multiple layers of Sub. When I try "Exit Sub", it just exit the current Sub layer, but return to the previous Sub layer. So, my question is how to exit the code ENTIRELY when a condition "BCDEA" is met?


Actually, I know that I can run the entire code first, then search "BCDEA" in the worksheet, and manually delete the rest. However, it may lead to a huge computational cost which discourages me to do so.


Sub ABCDE()
Dim x, y As Variant
    y = "ABCDE"
    x = ""
Call GetPermutation(x, y)
End Sub

Sub GetPermutation(ByVal x, ByVal y)
Dim i, j, CurrentRow As Integer
CurrentRow = Application.WorksheetFunction.CountA(Columns(1))
    j = Len(y)
    If j < 2 Then
        Cells(CurrentRow + 1, 1) = x & y

       If Cells(CurrentRow + 1, 1) = "BCDEA" then Exit Sub     
    Else
        For i = 1 To j
            Call GetPermutation(x + Mid(y, i, 1), Left(y, i - 1) + Right(y, j - i))
        Next
    End If
End Sub


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-1-1 20:32:24
只需要把 "Exit Sub" 改成 "End"。我试过,这样就可以遇到BCDEA就停下来。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群