Macro to sum doesn't work

R

RM270

I have numbers in Column G and Column I. I want to add the numbers and have
the results display in Column J. Like so:

G I J
2 2 4
5 3 8
1 9 10
I have set up a macro that does several things to the worksheet, and I want
it to automatically add the numbers. The number of row changes each time the
macro is run, which is once a week or so. Here is the code I have in the
macro, but it doesn't work. It adds all the numbers in Column G to all the
numbers in Column I which is not what i want. What am I doing wrong?

With ActiveSheet
lastrow = .Cells(.Rows.Count, "a").End(xlUp).Row
For i = 2 To lastrow
If IsNumeric(.Cells(i, "j").Value2) Then
.Cells(i, "j").Value2 = "=sum(g:g,i:i)"

End If

Next i
End With

Thanks for any and all help
 
J

Jacob Skaria

Try the below

Sub MyMacro()
Dim lngRow As Long
lngRow = Cells(Rows.Count, "I").End(xlUp).Row
Range("J2:J" & lngRow).Formula = "=G2+I2"
End Sub
 
R

RM270

Thank you so much Jacob. Works perfectly.

Jacob Skaria said:
Try the below

Sub MyMacro()
Dim lngRow As Long
lngRow = Cells(Rows.Count, "I").End(xlUp).Row
Range("J2:J" & lngRow).Formula = "=G2+I2"
End Sub
 

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

Top