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 19th, 2002, 09:54 AM   #1
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

I have two columns (A & B). I need to have in Column C to product of A & B, i.e. I need A * B in C. But the entire formula is A * B * D5 in C. Also, the length of the lists in A and B varies. I need a macro to do this:

Start on A1
IF AND(A1<>””,B1<>””)
THEN C1 = A1*B1*D5
Goto A2
IF AND(A2<>””,B2<>””)
THEN C2 = A2*B2*D5


How do I do this?
Cosmos75 is offline   Reply With Quote
Old Mar 19th, 2002, 09:59 AM   #2
smozgur
BatCoder
 
Join Date: Feb 2002
Location: Turkey
Posts: 764
Default


You can do it just like you said. you dont need macro i think. Just put this formula in C1 then copy the next rows:

=IF(AND(A1<>"",B1<>""),A1*B1*D$5)


smozgur is offline   Reply With Quote
Old Mar 19th, 2002, 10:14 AM   #3
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

You don't seem to need a macro, but this
will do if you insist...
Copy the stuff below in place of your
macro. I'm assuming that D5 is a common
factor for all rows????

Sub DoSomeMath()
Dim RowCntr as Long
Dim StaticNumber
StaticNumber = Range("D5").value

For RowCntr = 1 to 65500

If Range("A" & RowCntr) <> "" and _
Range("B" & RowCntr) <> "" Then

If Not IsNumeric(Range("A" & RowCntr) then
msgbox "Invalid Factor - Reference A" & _
RowCntr
ExitSub
End If

If Not IsNumeric(Range("B" & RowCntr) then
msgbox "Invalid Factor - Reference B" & _
RowCntr
ExitSub
End If

Range("C" & RowCntr).value = _
Range("A" & RowCntr).value * _
Range("B" & RowCntr).value * StaticNumber

End If

Next

End Sub

[ This Message was edited by: TsTom on 2002-03-19 09:16 ]

[ This Message was edited by: TsTom on 2002-03-19 09:17 ]
Tom Schreiner is offline   Reply With Quote
Old Mar 19th, 2002, 10:32 AM   #4
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Excel didn't recognize the ExitSub part.

Tried a simple version of your formula.
Range("D1").Value = Range("B1").Value * Range("C1").Value

Didn't work. Do I need to add a few "s somewhere?

I need a macro because I never know how long the two lists are going to be and this is part of a much bigger macro that actually generates the list by copying and pasting certain cells from several worksheets (worksheets are added and deleted often).



[ This Message was edited by: Cosmos75 on 2002-03-19 09:34 ]
Cosmos75 is offline   Reply With Quote
Old Mar 19th, 2002, 10:47 AM   #5
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Try the following code:

RowCounter = Intersect(ActiveSheet.UsedRange, Columns("A:B")).Rows.Count
For i = 1 To RowCounter
Range("c" & i).Value = Range("a" & i).Value * Range("b" & i).Value * Range("d5").Value
Next i

_________________
Hope this helps.
Kind regards, Al.

[ This Message was edited by: Al Chara on 2002-03-19 09:55 ]
Al Chara is offline   Reply With Quote
Old Mar 19th, 2002, 10:51 AM   #6
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

I got it to work BUT when it calculates Column C, it enters a value. In there anyway to change this to enter a formula intead of the value?

THANKS!!
Cosmos75 is offline   Reply With Quote
Old Mar 19th, 2002, 10:58 AM   #7
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

So you don't want the value. You just want the C5 cell to show, for example A5*B5*D5. Is this correct?
Al Chara is offline   Reply With Quote
Old Mar 19th, 2002, 11:04 AM   #8
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

If this is correct, try the following code:

RowCounter = Intersect(ActiveSheet.UsedRange, Columns("A:b")).Rows.Count
For i = 1 To RowCounter
If Range("a" & i).Value = "" Or Range("b" & i).Value = "" Then GoTo 1
Range("c" & i).Value = "A" & i & "*" & "B" & i & "*" & "D5"
1 Next i
__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old Mar 19th, 2002, 11:18 AM   #9
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

I do want the value, but I want the formula to be shown in Column C , i.e. =A1*B2*D5
Cosmos75 is offline   Reply With Quote
Old Mar 19th, 2002, 11:26 AM   #10
Dave Patton
Board Regular
 
Join Date: Feb 2002
Location: Calgary, Alberta Canada
Posts: 2,065
Default


A very concise example would have been very useful. The following example might be useful.

You do not have to use named ranges.
If your ranges contract or expand, cosider dynamic ranges.

Price Qty 7.00%
5.00 2.00
10.00 3.00
20.00 4.00
Total
128.40

The total is calculated with
=SUMPRODUCT((Price*Qty))*(1+Tax)

which could be

=SUMPRODUCT((a2:A100*B2:B100))*(1+D5)

Ensure that you use references or names cosistent with your data.
Dave Patton 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:43 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