GeneralFormula for Adding 2 Columns

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,
I am trying to add 2 columns and put the result in the
third column. I want this to happen for any number of
rows. If I populate X number of Rows then the result
should be in the third column.
I need help in this badly. I would appreciate if
somebody could tell me the fastest way. I am not
interested in the option where 2 numbers are added in the
first row and then the rest is taken care by dragging for
the rest of the rows in the same column.
Thanks in advance.

-John
 
You could try a macro like this:

Sub AddColumns()

Dim x As Integer

x = 1

While Range("A" & x).Value <> ""
Range("C" & x).Select
ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]"
x = x + 1
Wend

End Sub

This macro assumes the first column of number is in column A and the formula
is to go in column C. Change these as necessary.

HTH
Mike.
 
John,

You could try this and then assign a button to it.

Sub TestMe()
Dim sRow As Integer ' First row
sRow = 1 ' will start at row #1
Dim lRow As Long ' Last Row
lRow = Range("A" & sRow).End(xlDown).Row
Dim x As Long
x = sRow
For x = sRow To lRow
Range("C" & x).Formula = "=A" & x & "+B" & x
Next x
End Sub

John
 
Back
Top