MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Code for Summation

  Asked By: Donna    Date: Oct 26    Category: MS Office    Views: 1471

I have given a variable for the Number of last row. So this variable return
the No of th last row . Now i want to add all the values in a particular column
till the last row .

Could you please help me finding the code?



1 Answer Found

Answer #1    Answered By: Bathilda Schmidt     Answered On: Oct 26

Well done, you are halfway there. Use the macro recorder, and just do a
normal sum from row  1 to the end of your dataset. Look at the code, and
you will see that the default formula format is FormulaR1C1. But I just
want Formula. So I changed it slightly, and used the Concatenate
operator (&).

In your code, you will have defined LastCol through a different means.

Sub Macro1()
' Macro1 Macro

Dim LastCol
LastCol = 21
'ActiveCell.FormulaR1C1 = "=SUM(R[-21]C:R[-1]C)"
ActiveCell.Formula = "=sum(B1:B" & LastCol & ")"

End Sub

Didn't find what you were looking for? Find more on Code for Summation Or get search suggestion and latest updates.