MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Jan 14th, 2002, 04:47 PM   #1
Sam40mUK
Board Regular
 
Join Date: Mar 2002
Location: North Wales Coast, UK
Posts: 95
Default

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.
Sam40mUK is offline   Reply With Quote
Old Apr 12th, 2002, 03:22 PM   #2
Sam40mUK
Board Regular
 
Join Date: Mar 2002
Location: North Wales Coast, UK
Posts: 95
Default

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
Sam40mUK is offline   Reply With Quote
Old Apr 12th, 2002, 03:29 PM   #3
tk19
New Member
 
Join Date: Mar 2002
Posts: 33
Default

something like this
if activecell=cells(10,3) then...
might work, not sure...
tk19 is offline   Reply With Quote
Old Apr 12th, 2002, 03:37 PM   #4
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Quote:
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
Jay Petrulis is offline   Reply With Quote
Old Apr 12th, 2002, 03:55 PM   #5
Sam40mUK
Board Regular
 
Join Date: Mar 2002
Location: North Wales Coast, UK
Posts: 95
Default

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
Sam40mUK is offline   Reply With Quote
Old Apr 12th, 2002, 04:01 PM   #6
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
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.

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






_________________
Kind Regards,
Ivan F Moala
http://<font color="green"><a href="...r Construction

[ This Message was edited by: Ivan F Moala on 2002-04-12 15:04 ]
Ivan F Moala is offline   Reply With Quote
Old Apr 14th, 2002, 09:55 AM   #7
Sam40mUK
Board Regular
 
Join Date: Mar 2002
Location: North Wales Coast, UK
Posts: 95
Default

Hi All,
Sorry to be a pain but anyone got any ideas?
Cheers
S
Sam40mUK is offline   Reply With Quote
Old Apr 14th, 2002, 09:59 AM   #8
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

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
Jay Petrulis is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 04:14 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes