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 24th, 2002, 04:25 PM   #1
kwaring
New Member
 
Join Date: Mar 2002
Location: Nanaimo, BC
Posts: 49
Default

Range("A5").Select
ActiveCell.FormulaR1C1 = SUM(A1:A4)

Trying to do something like this but the compiler doesn't like the syntax... any suggestions?
Thanks,
Kyle

[ This Message was edited by: kwaring on 2002-03-24 17:13 ]
kwaring is offline   Reply With Quote
Old Mar 24th, 2002, 04:34 PM   #2
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Quote:
On 2002-03-24 15:25, kwaring wrote:
Range("A5").Select
ActiveCell.FormulaR1C1 = SUM(A1:A4)

Trying to do something like this but the compiler doesn't like the syntax... any suggestions?
Thanks,
Kyle
Hi Kyle,

Be sure to enclose the formula to load to the worksheet in quotes. Also, no need to select unles required, as it makes the code inefficient.

Range("A5") = "=SUM(A1:A4)"

would work for you.

Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Mar 24th, 2002, 04:36 PM   #3
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Try

ActiveCell.Formula = "=Sum(A1:A4)"

FormulaR1C1 expects a formula in relative reference format e.g. =Sum(r2c1,r3c4). For both you need to assign a string as the formula you want to use.

HTH,
D
dk is offline   Reply With Quote
Old Mar 24th, 2002, 05:45 PM   #4
kwaring
New Member
 
Join Date: Mar 2002
Location: Nanaimo, BC
Posts: 49
Default

Thanks Jay and dk, however, I am still having problems... Your code works on the simple examples above and I thought I could incorporate that into my more-complex code but it still doesn't work.

Range("E" & Search) = "=SUM("E" & Start & ":" & "E" & Search)"

Where Search and Start are variables defined in VBA. When I try to run the macro, I get a Run-time error '1004': Application-defined or object-defined error
Thanks,
Kyle
kwaring is offline   Reply With Quote
Old Mar 24th, 2002, 06:45 PM   #5
kwaring
New Member
 
Join Date: Mar 2002
Location: Nanaimo, BC
Posts: 49
Default

Actually looks like this:

Range("E" & Search + 1) = "=SUM("E" & Start & ":" & "E" & Search)"

I've tried:
Range("E" & Search + 1) = "=SUM('E' & Start & ':' & 'E' & Search)"

Still no luck
kwaring is offline   Reply With Quote
Old Mar 24th, 2002, 06:54 PM   #6
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi Kwaring

Try

Range("E" & Search + 1) = "=SUM(E" & Start & ":" & "E" & Search & ")"
Dave Hawley is offline   Reply With Quote
Old Mar 24th, 2002, 07:16 PM   #7
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
Default

Quote:
On 2002-03-24 15:25, kwaring wrote:
Range("A5").Select
ActiveCell.FormulaR1C1 = SUM(A1:A4)

Trying to do something like this but the compiler doesn't like the syntax... any suggestions?
Thanks,
Kyle

[ This Message was edited by: kwaring on 2002-03-24 17:13 ]
Hey Kyle:
Referring to the formula in your original posting, change it to:

Sub RangeAdd2()
Range("A5").Select
ActiveCell.Formula = "=sum(a1:a4)"
End Sub

Put the above sub in a module of your workbook. It works. The suggestions by Jay and dk given to you earlier do work.
So please check:
1) Install the SUB in a module of the Active Workbook
2) Check the SUB for editorial/syntax issues
3) Run the SUB

After you do the above post back what you get, VBA GURUs like Jay, dk, and Dave will be able to look at your SUB and point out where is what wrong.

_________________
Yogi Anand
Edit: Deleted inactive web site reference from hard coded signature

[ This Message was edited by: Yogi Anand on 2003-01-19 15:17 ]
Yogi Anand is offline   Reply With Quote
Old Mar 24th, 2002, 07:20 PM   #8
kwaring
New Member
 
Join Date: Mar 2002
Location: Nanaimo, BC
Posts: 49
Default

That works perfectly, Dave... THANK YOU!
kwaring is offline   Reply With Quote
Old Mar 24th, 2002, 07:37 PM   #9
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
Default

Quote:
On 2002-03-24 16:45, kwaring wrote:
Thanks Jay and dk, however, I am still having problems... Your code works on the simple examples above and I thought I could incorporate that into my more-complex code but it still doesn't work.

Range("E" & Search) = "=SUM("E" & Start & ":" & "E" & Search)"

Where Search and Start are variables defined in VBA. When I try to run the macro, I get a Run-time error '1004': Application-defined or object-defined error
Thanks,
Kyle
Hi Kyle:
Sorry about my last belated post. In reference to the formula, try the following formula:

="Range(""E"&search+1&""")=""=sum(E"&start&":E"&search&")"""

results in
Range("E5")="=sum(E1:E4)"

HTH

_________________
Yogi Anand
Edit: Deleted inactive web site reference from hard coded signature

[ This Message was edited by: Yogi Anand on 2003-01-19 15:18 ]
Yogi Anand 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 10:13 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