Copy sum of values from one sheet to another

Closed
bj - Oct 19, 2010 at 12:59 PM
venkat1926 Posts 1864 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Oct 20, 2010 at 09:26 PM
Hello,

I am writing a VB .net code to copy sum of values in a column "O" of sheet 1 to the first empty cell in a row "6". I have written the following code till now and it doesnt work. Please let me know what went wrong. I need to do this asap. Please help.

sLastRow = oSheet1.Cells(oBook1.Worksheets(1).rows.count, "O").end(Excel.XlDirection.xlUp)
dLastRow = oSheet2.Range("A6").End(Excel.XlDirection.xlToRight)
dLastRow.Copy(sLastRow)

I have tried many ways to change my code but nothing worked. Any suggestions, help or pointers would be appreciated. Thanks


3 replies

venkat1926 Posts 1864 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 810
Oct 20, 2010 at 06:21 AM
quote

sLastRow = oSheet1.Cells(oBook1.Worksheets(1).rows.count, "O").end(Excel.XlDirection.xlUp)
dLastRow = oSheet2.Range("A6").End(Excel.XlDirection.xlToRight)
dLastRow.Copy(sLastRow)
unquote

Yo;u have not explained what you want to do It is difficult to GUESS what you are thinking to do just from the code statements you have given .please repost
0
Hi Venkat,

I have sheet1 which has a column "O". I need to sum the values in this coulumn.
I have sheet2 which has row index "6". I need to append the sum (calculated earlier in sheet1 ) to row 6 of sheet2. Row 6 already has some values. I need to append the sum of values in Column "O" in sheet1 to sheet2. And this I need to do for every month.
Please give some pointers on the same.

Thanks.
0
venkat1926 Posts 1864 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 810
Oct 20, 2010 at 09:26 PM
my sample workbook with sheet1 and sheet2 download from this webpage

http://www.speedyshare.com/files/24796632/BJ.xls

I ran this macro (the macro is in standard module of this workbook)
see whether you got what you want.(see sheet2cell O6) You said every month. what does that signify. do you have different workbook for different month
use the same macro



Sub test()
Dim j As Double, r As Range
With Worksheets("sheet1")
Set r = Range(.Range("O2"), .Range("O2").End(xlDown))
'MsgBox r.Address
j = WorksheetFunction.Sum(r)
'MsgBox j
End With
With Worksheets("sheet2")
.Cells(6, "O") = j
End With
End Sub
0