![]() |
Need Macro to Sum Range and Paste the Value into one Cell
Can anyone help with the Excel VB syntax to sum a range and paste the value into one cell. The following code is not working for me: Sheets("Sheet1").sum(Range("F36:f45")) Range("e88").Offset(X, 0).Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Note: the above syntax is in a loop. Thus, the need for Offset(x, 0) |
Need Macro to Sum Range and Paste the Value into one Cell
Dim myTotal as double mytotal = application.sum(worksheets("sheet1").range("f36:f4 5")) worksheets("sheetnamehere").range("e88").offset(x, 0).value = mytotal I'm not sure how the loop fits in. Mike wrote: Can anyone help with the Excel VB syntax to sum a range and paste the value into one cell. The following code is not working for me: Sheets("Sheet1").sum(Range("F36:f45")) Range("e88").Offset(X, 0).Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Note: the above syntax is in a loop. Thus, the need for Offset(x, 0) -- Dave Peterson |
Need Macro to Sum Range and Paste the Value into one Cell
You don't have to copy & paste special in this case; you can just assign the
sum of the range to the specified cell. Here are two versions: Sheets("Sheet1").Range("F36:F45").Select Range("E88").Offset(x, 0).Value = Application.WorksheetFunction.Sum(Selection) Range("E88").Offset(x, 0).Value = _ Application.WorksheetFunction.Sum(Sheets("Sheet1") .Range("F36:F45")) Unless you change the 36:F45 range each time, you are going to put the same total in a destination cell with every loop. Hope this helps, Hutch "Mike" wrote: Can anyone help with the Excel VB syntax to sum a range and paste the value into one cell. The following code is not working for me: Sheets("Sheet1").sum(Range("F36:f45")) Range("e88").Offset(X, 0).Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Note: the above syntax is in a loop. Thus, the need for Offset(x, 0) |
All times are GMT +1. The time now is 02:49 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com