Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refer to Range by cells’ numbers 2

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,486
5
38
US
I need to Sum cells in a Range, i.e. from B2 to AB2 and put a Sum in Cell AC2, but I know the row number and the column number, so I would like to use Sum Range from Cells(2, 2) to Cells(2, 28)

Having trouble with the syntax. Any ideas?



---- Andy

There is a great need for a sarcasm font.
 
Hi,

"Sum Range from Cells(2, 2) to Cells(2, 28)"

Assuming that the sheet you're referencing is active...
Code:
nSum = Application.Sum(Range(Cells(2, 2), Cells(2, 28)))

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Thanks,

This is what I came up with, when my Row is intR, start column is 2 and last Column is intLastCol:

Code:
Cells(intR, intLastCol + 1).Value = WorksheetFunction.Sum(Range(Cells(intR, 2), Cells(intR, intLastCol)))

Which is the same as what you gave me :)

What about if - instead of calculating the Sum, I would enter the Formula for Sum?


---- Andy

There is a great need for a sarcasm font.
 
Cells(intR, intLastCol + 1).FormulaR1C1 = "=SUM(R" & intR & "C2:R" & intR & "C" & iIntLastCol & ")"

combo
 
Thanks combo, works like a charm.... [pc2]



---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top