Summing a column using a macro (Done by XL GURU)

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

PincivMa

Thread Starter
Joined
Mar 13, 2004
Messages
378
Hi There

The attached spreadsheet shows 3 macros. Each one sums numbers in columns B, C and D. This macro was given to me be Andy quite a while ago. I believe he went by the name of XL GURU. The macros work great in every column except column C. You can run the macros and you will see what I'm talking about. Why is the macro that sums column C not adding Column C? How can I fix it??

Mario
 

Attachments

Joined
Jul 28, 2006
Messages
1,223
It's because FormulaR1C1 property is used. In this kind of cell referencing "C" is a special character, it referes to columns. So "SUM(C5:C10)" means summing columns 5 through 10, that is $E:$J.
Replace one line in the code with this:
ActiveCell.Formula = "=sum(C" & n & ":C" & ActiveCell.Row - 1 & ")"
 
Joined
Jul 1, 2005
Messages
8,546
Whoever gave you that code clearly had more coding enthusiasm than know-how.

For the data you provided, the following should create a SUM formula 2 cells below the last used cell in whichever column is "active" at the time.

HTH,
bomb ("XL Guru" in a previous existence :eek: )

Sub Sum2Below()
x = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row + 2
Cells(x, ActiveCell.Column) = "=SUM(" & Cells(5, ActiveCell.Column).Address & ":" & _
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Address & ")"
End Sub
 

PincivMa

Thread Starter
Joined
Mar 13, 2004
Messages
378
Hi Bomb # 21 and Jimmy the Hand

Jimmy the hand: Thanks for the clarification between ActiveCell.Formula and ActiveCell.FormulaR1C1. It now makes sense.

Bomb # 21: Thank you for a new way of summing totals.

Mario
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top