1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Business Applications' started by PincivMa, Jan 28, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. PincivMa

    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
     

    Attached Files:

  2. Jimmy the Hand

    Jimmy the Hand

    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 & ")"
     
  3. bomb #21

    bomb #21

    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
     
  4. PincivMa

    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
     
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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/539214

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice