Need Macro to Sum Range and Paste the Value into one Cell

M

Mike

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)
 
D

Dave Peterson

Dim myTotal as double
mytotal = application.sum(worksheets("sheet1").range("f36:f45"))
worksheets("sheetnamehere").range("e88").offset(x,0).value = mytotal

I'm not sure how the loop fits in.
 
T

Tom Hutchins

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
 

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