Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Macro to sum doesn't work

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Macro to sum doesn't work

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

--
Jacob


"RM270" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Macro to sum doesn't work

Thank you so much Jacob. Works perfectly.

"Jacob Skaria" wrote:

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

--
Jacob


"RM270" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro will not work - Please help JayLatimer Excel Discussion (Misc queries) 4 January 29th 10 10:30 PM
Macro to update a column in a work based on another work sheet WickerMan New Users to Excel 1 December 4th 09 12:58 PM
Macro works Macro does not work Wanna Learn Excel Discussion (Misc queries) 4 March 24th 08 12:51 PM
Why Won't This Macro Work? Pausert of Nikkeldepaiin Excel Discussion (Misc queries) 7 February 4th 08 01:05 PM
how to get a macro to work Danny Excel Discussion (Misc queries) 8 August 20th 07 01:30 PM


All times are GMT +1. The time now is 08:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"