chacanger
11-19-2012, 04:19 PM
Hello
I've been wondering if there was a simple way of doing this, I have a lot of code were there are multiple procedures being opened within other procedures and multiple bits of looping code. I have made a rough example below of what I mean...
Option Explicit
Dim x As Byte, z As Byte
Sub ProcedureOne()
Do Until x = 4
Do Until z = 3
ProcedureTwo
z = z + 1
Loop
Loop
Msgbox "x = 4"
End Sub
Sub ProcedureTwo()
ProcedureThree
End Sub
Sub ProcedureThree()
x = 4
End Sub
As you can see there are 2 loops and 2 procedures nested within each other, Is there a way once x = 4, rather than having to put an If statement saying when it reaches 4 Exit Sub, then have another If statement on the first procedure when it reaches 4 Exit Do, just have it so that when x does = 4, it goes straight to the part with the Msgbox when it's in ProcedureThree.
Obviously the code I actually have is 100 times longer due to many different things going on, so it's not as simple as this bit of code, but if I can get a rough idea on how to do it, I can do the rest. I get an idea it would be something like an event such as Workbook_WindowActivate were it activates as soon as something happens.
Sorry if this doesn't make sense, I couldn't describe it very easily.
Many Thanks
Chacanger
I've been wondering if there was a simple way of doing this, I have a lot of code were there are multiple procedures being opened within other procedures and multiple bits of looping code. I have made a rough example below of what I mean...
Option Explicit
Dim x As Byte, z As Byte
Sub ProcedureOne()
Do Until x = 4
Do Until z = 3
ProcedureTwo
z = z + 1
Loop
Loop
Msgbox "x = 4"
End Sub
Sub ProcedureTwo()
ProcedureThree
End Sub
Sub ProcedureThree()
x = 4
End Sub
As you can see there are 2 loops and 2 procedures nested within each other, Is there a way once x = 4, rather than having to put an If statement saying when it reaches 4 Exit Sub, then have another If statement on the first procedure when it reaches 4 Exit Do, just have it so that when x does = 4, it goes straight to the part with the Msgbox when it's in ProcedureThree.
Obviously the code I actually have is 100 times longer due to many different things going on, so it's not as simple as this bit of code, but if I can get a rough idea on how to do it, I can do the rest. I get an idea it would be something like an event such as Workbook_WindowActivate were it activates as soon as something happens.
Sorry if this doesn't make sense, I couldn't describe it very easily.
Many Thanks
Chacanger