![]() |
|
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
|
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() 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. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,517
|
Any way to avoid using sendkeys?
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
|
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). |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,517
|
What about using a ControlID? (bed-time for me, I'm trying to be difficult on purpose now)
|
|
|
|
|
|
#5 |
|
Banned
Join Date: Mar 2002
Posts: 1,582
|
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 ] |
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
|
Wow that's REALLY ugly Dave
AND GUESS WHAT... HA, FOUND A WAY... it's really cool, simple, same "principle" as in 2000, but with a twist. Sub TestAutoSumXP() 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() |
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,517
|
[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) |
|
|
|
|
|
#8 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
|
Quote:
|
|
|
|
|
|
|
#9 |
|
Banned
Join Date: Mar 2002
Posts: 1,582
|
Ugly you say! You have never seen me IRL have you, then you will no what ugly is
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
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 |
|
|
|
|
|
#10 |
|
Join Date: Aug 2006
Posts: 1
|
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
Thanks, Nick |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|