Conditional If Statement in Macro calling Sub Routine

Sam40mUK

Board Regular
Joined
Mar 18, 2002
Messages
95
Hi again,
Thank you for responses, I appreciate you taking the time to help.
I notice from the examples posted the If, Then, Else Statement appears to draw a line under the Sub Routine and the conditions and in effect diverts to various other Sub Routines.
I have code below a simple:

If ActiveCell.Address = "$C$65536" Then Macro1

Things are not working too well .. it appears that it performs Macro1 if the condition is True and then Returns to the original code below the If statement and executes that.
I am wondering if I therefore have to do an If, Then, Else with a False condition returning to another Subroutine to finish the procedure?
I am sorry if I am making 'heavy weather' of this but it the end of a long week!
Regards
S.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Evening all,

I am currently trying to test to see if a Cell is, say C10 and if it is then 'branch' to another Subroutine. If the cell is not C10 I assume the If statement will be false and the 'original' macro will continue.

Can anyone please give an example of an If statement. Many thanks in advance.
S
 
Upvote 0
On 2002-04-12 14:22, Sam40mUK wrote:
Evening all,

I am currently trying to test to see if a Cell is, say C10 and if it is then 'branch' to another Subroutine. If the cell is not C10 I assume the If statement will be false and the 'original' macro will continue.

Can anyone please give an example of an If statement. Many thanks in advance.
S

Hi,

Here is a simple example.
Sub test()
If ActiveCell.Address= "$C$10" Then
test1
Else
test2
End If
End Sub

Sub test1()
MsgBox "TRUE"
End Sub

Sub test2()
MsgBox "FALSE"
End Sub
 
Upvote 0
Hi Jay,
Once again thanx for your response to my posting, that was just what I was looking for a simple explanation.
I am looking to complete the Subroutine and NOT return to the original macro. I have incorporated the If statement and it appears to return to the original macro, there again it could be me! As usual any advice would be appreciated.
Cheers.
S
 
Upvote 0
On 2002-04-12 14:55, Sam40mUK wrote:
Hi Jay,
Once again thanx for your response to my posting, that was just what I was looking for a simple explanation.
I am looking to complete the Subroutine and NOT return to the original macro. I have incorporated the If statement and it appears to return to the original macro, there again it could be me! As usual any advice would be appreciated.
Cheers.
S

In the called macro just add End as your finishing statement

eg.<pre/>
If vbYes = MsgBox("Select YES to Goto [Sheet1]" & vbCrLf _
& "Select NO to Goto [Sheet2]", vbYesNo) Then
Sheets("Sheet1").Select
Else
Sheets("Sheet2").Select
End If
End</pre>





_________________
Kind Regards,<font size=+2><font color="red"> I<font color="blue">van<font color="red"> F M</font color="blue">oala</font></font></font>
<font color="green">[url]http://www.gwds.co.nz/ - Under Construction[/url]
This message was edited by Ivan F Moala on 2002-04-12 15:04
 
Upvote 0
Hi,

If ActiveCell.Address = "$C$65536" Then

Macro1
Exit Sub

End if

This will break out of the routine. It will run Macro1, then return to this calling sub and then exit it.

HTH,
Jay
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,920
Members
448,533
Latest member
thietbibeboiwasaco

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top