MrExcel Message Board
Support This Site


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 Jul 20th, 2002, 04:23 AM   #1
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
Default

If you need it (Altough I would recommend other ways of doing this) here's the code to use the AutoSum button in Excel XP.

Sub TestAutoSumXP()
Application.CommandBars.FindControl(ID:=226).Execute
Application.SendKeys "S{Enter}"
End Sub


The difference between this and previous versions is that in previous versions you needed to do a "double" execute of the CommandBarButton in order to get the result. Now, in XP, since you have other Autofunctions (AutoAverage, Autocount,etc.), the problem is a little different, but not that much.

I really hope that using Sendkeys doesn't create a mess for anyone, but, hopefuly, it won't.
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Jul 20th, 2002, 04:28 AM   #2
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,517
Default

Any way to avoid using sendkeys?
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Jul 20th, 2002, 04:38 AM   #3
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
Default

Looking into it Mark, but, my recommendation would be to use something like this:

Rng.FormulaR1C1 = "=SUM(R[-1]C:R2C)"

which would execute faster, and without using sendkeys... only "problem" for this method is that you "have" to know the top row of the data (R2 in my example).
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Jul 20th, 2002, 04:47 AM   #4
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,517
Default

What about using a ControlID? (bed-time for me, I'm trying to be difficult on purpose now)
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Jul 20th, 2002, 04:54 AM   #5
Dave Hawley
Banned
 
Join Date: Mar 2002
Posts: 1,582
Default

Now if you guys only subscribed to my free newsletter you would know all this stuff

Code:
Sub SumUp()
Dim strAddress As String

strAddress = _
Range("A1", Range("A65536").End(xlUp)).Address

 If Range(strAddress).Cells.Count > 1 Then
    Range("A65536").End(xlUp).Offset(1, 0).Formula = _
                         "=Sum(" & strAddress & ")"
 End If
End Sub


Sub SumDown()
Dim strAddress As String

strAddress =Range("A2", Range("A65536").End(xlUp)).Address

 If Range(strAddress).Cells.Count > 1 Then
     Range("A1").Formula ="=Sum(" & strAddress & ")"
 End If
End Sub


Sub SumRight()
Dim strAddress As String

strAddress =Range("B1", Range("IV1").End(xlToLeft)).Address

 If Range(strAddress).Cells.Count > 1 Then
    Range("A1").Formula = "=Sum(" & strAddress & ")"
 End If
End Sub


Sub SumLeft()
Dim strAddress As String

strAddress =Range("A1", Range("IV1").End(xlToLeft)).Address
 If Range(strAddress).Cells.Count > 1 Then
      Range("IV1").End(xlToLeft).Offset(0, 1).Formula = _
                             "=Sum(" & strAddress & ")"
 End If
End Sub

Taken from Issue 14
http://www.ozgrid.com/News/Archive.htm



_________________
Regards
Dave Hawley
8 Add-ins 1, with free File Size Reducer
40+ more here
OzGrid.com

[ This Message was edited by: Dave Hawley on 2002-07-19 23:56 ]
Dave Hawley is offline   Reply With Quote
Old Jul 20th, 2002, 04:59 AM   #6
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
Default

Wow that's REALLY ugly Dave and you want to know something ? you really ought to take a look at your subscribers list... you may find some surprises.

AND GUESS WHAT... HA, FOUND A WAY... it's really cool, simple, same "principle" as in 2000, but with a twist.

Sub TestAutoSumXP()
Application.CommandBars("Auto Sum").Controls(1).Execute
Application.CommandBars("Auto Sum").Controls(1).Execute
End Sub


That will work perfectly. Now, here's the funny thing, the Controls(1) CommandBarButton is actually the AutoSum, If I check it like this:

?Application.CommandBars("Auto Sum").Controls(1).Id
226

I get 226, which is the same Id for the AutoSum in the Standard toolbar... BUT, this code WILL NOT work the same as the above... how's that?

Sub TestAutoSumXP2()
Application.CommandBars.FindControl(ID:=226).Execute
Application.CommandBars.FindControl(ID:=226).Execute
End Sub

__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Jul 20th, 2002, 05:04 AM   #7
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,517
Default

[quote]
Now if you guys only subscribed to my free newsletter you would know all this stuff [/quote/

I've hit your site about 20 times today. I'm not giving you another one just to sign up for a newsletter.

Juan,

You took your time coming up with that one. I bet Colo would have been able to tell you that.

(seriously though, good job)
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Jul 20th, 2002, 05:08 AM   #8
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
Default

Quote:
On 2002-07-20 00:04, Mark O'Brien wrote:
You took your time coming up with that one. I bet Colo would have been able to tell you that.
Well, if he had XP then probably... but that's not the reality right now, so sorry
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Jul 20th, 2002, 06:36 AM   #9
Dave Hawley
Banned
 
Join Date: Mar 2002
Posts: 1,582
Default

Ugly you say! You have never seen me IRL have you, then you will no what ugly is Me thinks it's quite elegant, you do realise it's 4 seperate procedures don't you?

Code:
Sub SumUp()
Dim strAddress As String

strAddress = _
Range("A1", Range("A65536").End(xlUp)).Address

 If Range(strAddress).Cells.Count > 1 Then
    Range("A65536").End(xlUp).Offset(1, 0).Formula = _
                         "=Sum(" & strAddress & ")"
 End If
End Sub
Mine has one up on the AutoSum, in that mine looks past any blank cells.

Juan, does Bill know your on my newsletter list? Or is he on there as well?

Mark, I have been getting all excited lately as the 20 hits per day (from you) means my traffic has DOUBLED! Why did you go and burst my bubble

Dave Hawley is offline   Reply With Quote
Old Aug 21st, 2006, 07:59 PM   #10
njones4213
 
Join Date: Aug 2006
Posts: 1
Default

Sorry to bump a really really old thread, but this has been driving me insane. I'm trying to do this very similar to what was posted, but it will not work for me. There are several groups on the sheet that I need to sum. I have already subtotaled the sheet so I cannot use that function. I cannot use some of the more creative solutions on here as the start at the bottom and go to the first non blank line.... I have many groups and will have to repeat the procedure for each of them. When I try using the

Code:
Application.CommandBars("Auto Sum").Controls(1).Execute
All I receive is the Sum function. No range is selected and therefore will still require user interaction. I know this is a bit vague, but I am at the end of my rope here.

Thanks,
Nick
njones4213 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 +1. The time now is 05:29 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2010 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