Sum columns Dynamics

166 views
Skip to first unread message

Michael Pablo

unread,
Sep 26, 2013, 12:14:58 PM9/26/13
to excelvb...@googlegroups.com
Hello!

I would like some Help with something that I want to try. I want to sum som columns with values and give a total, but I don't Know with there are a function for this analyse till the End and Put the result in the last row before the last cell with value of the column.

Thank you in advance,

Michael

koul....@gmail.com

unread,
Sep 26, 2013, 12:24:12 PM9/26/13
to excelvb...@googlegroups.com
Can u pls share a sample file
Sent on my BlackBerry® from Vodafone

From: Michael Pablo <skypa...@gmail.com>
Date: Thu, 26 Sep 2013 09:14:58 -0700 (PDT)
Subject: [Excel-VBA-Macros] Sum columns Dynamics
--
----------------------------------------------------------------------------------------------------------------------
You received this message because you are subscribed to the Google
Groups "Excel VBA Codes & Macros" group.
 
To post to this group, send email to
excelvb...@googlegroups.com
 
To unsubscribe from this group, send email to
excelvbamacro...@googlegroups.com
 
For more options, visit this group at
http://groups.google.com/group/excelvbamacros
---
You received this message because you are subscribed to the Google Groups "Excel VBA Macros" group.
To unsubscribe from this group and stop receiving emails from it, send an email to excelvbamacro...@googlegroups.com.
To post to this group, send an email to excelvb...@googlegroups.com.
Visit this group at http://groups.google.com/group/excelvbamacros.
For more options, visit https://groups.google.com/groups/opt_out.

rajan verma

unread,
Sep 26, 2013, 12:45:16 PM9/26/13
to excelvb...@googlegroups.com

Select headers and try this 


Sub TotalColumns()
    
    Dim rngRange As Range
    Dim rngCell As Range
    
    If TypeName(Selection) = "Range" Then
    Set rngRange = Selection
        For Each rngCell In rngRange.Cells
            Cells(Cells(Rows.Count, rngCell.Column).End(xlUp).Row + 1, rngCell.Column).Formula = "=Sum(" & rngCell.Address & ":" & Cells(Cells(Rows.Count, rngCell.Column).End(xlUp).Row, rngCell.Column).Address & ")"
            Cells(Cells(Rows.Count, rngCell.Column).End(xlUp).Row, rngCell.Column).Font.Bold = True
        Next rngCell
    End If
End Sub

--
Regards
Rajan verma
+91 7838100659

Michael Pablo

unread,
Sep 27, 2013, 2:01:04 PM9/27/13
to excelvb...@googlegroups.com
Gentlemen,

Thanks for help me. I Post here a example of my spreadsheet.

I have tested this code and it is satisfatory, they get the ideia Rajan... but I Can put a Header I didn't Understand how can I address the cells of the collumns to sum, apparently is sum the cell above just it and didn't Sum, is Pretty weird at first.

Thanks,

Michael
teste.xlsm

Michael Pablo

unread,
Oct 3, 2013, 9:05:11 AM10/3/13
to excelvb...@googlegroups.com
Hello Rajan,

I didn't understand where I will put a range. Can you explain to me how could do this?

Thanks in advance,

Michael

Em quinta-feira, 26 de setembro de 2013 13h45min16s UTC-3, rajanverma1987 escreveu:

ashish koul

unread,
Oct 3, 2013, 10:16:25 AM10/3/13
to excelvbamacros
HI Michael

Please share the sample workbook
Ashish Koul




P Before printing, think about the environment.

 

Michael Pablo

unread,
Oct 3, 2013, 12:59:44 PM10/3/13
to excelvb...@googlegroups.com
Hello Ashish,

Follow a sample with the code of Rajan and some data at the table.

Warm Regard,

Michael
Soma de Colunas dinamicamente.xlsm

ashish koul

unread,
Oct 3, 2013, 1:05:54 PM10/3/13
to excelvbamacros
Sub sum_cols()
    Dim i As Long
    Dim j As Long
    j = Range("a1048576").End(xlUp).Row + 1
    For i = Range("e7").Column To Range("p7").Column
        Cells(j, i).Formula = "=sum(" & Cells(2, i).Address & ":" & Cells(j - 1, i).Address & ")"
    Next
End Sub

rajan verma

unread,
Oct 3, 2013, 1:10:22 PM10/3/13
to excelvb...@googlegroups.com
you have to selection your data headers before you run this macro.. 
this will do sum at the end of all columns, i am not sure if it was the answer of you query , but you can try :)

Michael Pablo

unread,
Oct 3, 2013, 1:34:25 PM10/3/13
to excelvb...@googlegroups.com
Now I understand, but It almost what I want, because the lines will be increase all the time and I would like to do this.

Ashish, Thank you very much for your support! It worked the way I wanted.

Kind Regards,

Michael
Reply all
Reply to author
Forward
0 new messages