VB script to sum up amount

  • Thread starter Thread starter tanks1308
  • Start date Start date
T

tanks1308

Hi, can anybody help me on this? I've trying to figure out how to sum up
the amount in a column. I've a source file, everytime the data in the
source file can be varied, meaning the amount in the file is not fixed.


By this, how to write a script to sum up all the amount and the total
will be below.

Hope you understand what I am trying to say.

Cheers.
 
One way:

In a new module, enter this macro, and change Sheet1 to the neam of your
worksheet, and the "A" in "A65536" to the column you need to sum.

Option Explicit

Sub Summit()
Dim lngRow As Long
Dim rngX As Excel.Range

' find the end of the list
Set rngX = Sheet1.Range("A65536").End(xlUp).Offset(1, 0)
lngRow = rngX.Row - 1
rngX.FormulaR1C1 = "=SUM(R[-" & Trim$(CStr(lngRow)) & "]C:R[-1]C)"
End Sub


Alan P.
 
This line:
rngX.FormulaR1C1 = "=SUM(R[-" & Trim$(CStr(lngRow)) & "]C:R[-1]C)"

could be written:
rngX.FormulaR1C1 = "=SUM(R[-" & lngRow & "]C:R[-1]C)"

And maybe just:
rngX.FormulaR1C1 = "=SUM(R1C:R[-1]C)"
to start at row 1 through the row above.


Alan said:
One way:

In a new module, enter this macro, and change Sheet1 to the neam of your
worksheet, and the "A" in "A65536" to the column you need to sum.

Option Explicit

Sub Summit()
Dim lngRow As Long
Dim rngX As Excel.Range

' find the end of the list
Set rngX = Sheet1.Range("A65536").End(xlUp).Offset(1, 0)
lngRow = rngX.Row - 1
rngX.FormulaR1C1 = "=SUM(R[-" & Trim$(CStr(lngRow)) & "]C:R[-1]C)"
End Sub

Alan P.

tanks1308 said:
Hi, can anybody help me on this? I've trying to figure out how to sum up
the amount in a column. I've a source file, everytime the data in the
source file can be varied, meaning the amount in the file is not fixed.


By this, how to write a script to sum up all the amount and the total
will be below.

Hope you understand what I am trying to say.

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top