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 Mar 15th, 2002, 04:46 PM   #1
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

I want to make a macro. I have 8 variables (x1 to x8) that I want to be able to add up to a constant value by changing one or even more then one but not the others.

E.g. (x1*1.1)+ (x2*1.2)+ (x3*1.3)+ (x4*1.4)+ (x5*1.5)+ (x6*1.6)+ (x7*1.7)+ (x8*1.=120

I have the Variable (x1 to x8) listed in Column A and the multipliers (1.1 to 1. in Column B.

How can I change x1 have the other change appropriately? Or change a few variables and have the others change appropriately?

Each variable has a lower limit that they cannot go under and an upper limit that cannot go over. For example, x5 has to be between 5 and 40.

Also, each variable cannot be a negative number.

Is there I way I can do this?

FANTASY REQUEST:
One more request, although this certainly isn’t necessary. Is there anyway to add a scroll-bar to each variable, whereby if I move one scroll-bar, the others move accordingly? Just curious to see if it could be done. (A scroll-bar from the forms tool-box where you can link a cell to it and move the “scroller” or click the arrows on the scroll-bar to change the value in the cell in specified increments and with a lower and upper limit is what I mean.)

Note: That smiley face is 8 )

[ This Message was edited by: Cosmos75 on 2002-03-15 15:48 ]
Cosmos75 is offline   Reply With Quote
Old Mar 15th, 2002, 10:41 PM   #2
Damon Ostrander
MrExcel MVP
 
Damon Ostrander's Avatar
 
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
Default

Hi Cosmos75,

Yes, you can do all of this. I take it that you want to be able to edit any one of the variables and have all the others automatically calculate to satisfy the equation. Of course, this cannot be done with cell formulae because the instant you enter a value in a cell with a formula it will wipe out the formula. It has to be done via worksheet events, namely the Change event. With the Change event you can determine (using the Target argument) which of the variables (cells) has been edited, and recalculate the others. Of course, you must have the algorithm to do this, and I assume you do. The mathematical problem here is that it appears there will be many solutions to the equation, not just one, especially if the variables do not have to be integers. But again, I assume you have all that worked out.

The one part that is questionable is limiting the range of the variables. What if there is no solution unless the solution for one of the variables goes outside its range? What would you want the program to do in this case? The easiest thing would be just to show a message saying there is no solution within the variable range, and set the entry cell back to its original value.

Regarding using the spinners to change the values, this is quite easy, especially if the variables are integer values. Just assign the spinner value (which is an integer that goes from the spinner's Min property value to its Max property value) to the variable, textbox, cell, or wherever you want to put it. If the variable is not an integer you will have to decide on a fixed step size by which the variable will change with each step of the spinner since it always steps by one. So, for example, if you want it to step by 0.25 you would multiply the spinner's Value property by 0.25 before assigning it to the variable, textbox, or cell that corresponds with that variable.

I hope this is helpful.
__________________
Keep Excelling.

Damon

VBAexpert Excel Consulting
(My other life: http://damonostrander.com )
Damon Ostrander is offline   Reply With Quote
Old Mar 18th, 2002, 11:45 AM   #3
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

I am afriad I don't know what a Change Event is or even what a worksheet event is??

Is that an add-in for Excel??
Cosmos75 is offline   Reply With Quote
Old Mar 18th, 2002, 01:55 PM   #4
Damon Ostrander
MrExcel MVP
 
Damon Ostrander's Avatar
 
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
Default

Hi again Cosmos75,

These events are Excel features that can be accessed via Visual Basic for Applications (VBA) code. The Change event, for example, enables one to write VBA code that does something whenever the value of a cell is manually changed. So, instead of using a formula to modify cell B1 whenever A1 changes, you could using VBA code calculate the valueof B1 when A1 changes, but at the same time the code could also calculate the value of A1 if B1 changes. This is something you can't do with a formula. I could send you an example if you like.
__________________
Keep Excelling.

Damon

VBAexpert Excel Consulting
(My other life: http://damonostrander.com )
Damon Ostrander is offline   Reply With Quote
Old Mar 18th, 2002, 02:46 PM   #5
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Sure, it would be extremely helpfull. Would it contain examples of formulas to add things?

Could included a simple Average,Max, and Sum Funtions syntax?

There is one thing that came to mind. If I wanted to add the Sum of a list in Column A or determin the Max and have the sum/max put at the bottom of the list, would the Event keep on running since a value (sum/max) is added to the end of the list? An Event is recursive, correct? [Did some research online about Events]

Thanks for your help!
Cosmos75 is offline   Reply With Quote
Old Mar 19th, 2002, 01:38 PM   #6
Damon Ostrander
MrExcel MVP
 
Damon Ostrander's Avatar
 
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
Default

Hi again Cosmos75,

Yes, you can do Max, Avg, Sum functions this way, but not using in-cell functions. It's a bit hard to explain, but easy to demonstrate.

Regarding recursion, this is a common problem for those implementing events for the first time, but it is actually easily handled. Unfortunately the Excel help files do not provide a warning on this, or any explanation of how to get around it, and this is probably the main reason why so many users struggle with it. I have put numerous postings on the board in the past showing how to eliminate this problem.

Damon
__________________
Keep Excelling.

Damon

VBAexpert Excel Consulting
(My other life: http://damonostrander.com )
Damon Ostrander is offline   Reply With Quote
Old Mar 19th, 2002, 01:43 PM   #7
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Also, of less importance, you can check "Disable Smilies on this Post" at the bottom of this form to show things like 8) or
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old Mar 19th, 2002, 04:15 PM   #8
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Quote:
On 2002-03-19 12:38, Damon Ostrander wrote:
Hi again Cosmos75,

Yes, you can do Max, Avg, Sum functions this way, but not using in-cell functions. It's a bit hard to explain, but easy to demonstrate.

Regarding recursion, this is a common problem for those implementing events for the first time, but it is actually easily handled. Unfortunately the Excel help files do not provide a warning on this, or any explanation of how to get around it, and this is probably the main reason why so many users struggle with it. I have put numerous postings on the board in the past showing how to eliminate this problem.

Damon
Cool. Although I have no knowledge of how to write code for Events. Any simple examples of Adding, Multiplying, Averageing, Max? Are choosing Ranges like that in VBA? Any good place for me to start?
Cosmos75 is offline   Reply With Quote
Old Apr 2nd, 2002, 09:52 AM   #9
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Finally got some code as a stating point, see link below.

http://www.mrexcel.com/board/viewtop...c=3782&forum=2
Cosmos75 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 11:35 AM.


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