View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone[_2_] Jim Cone[_2_] is offline
external usenet poster
 
Posts: 1,549
Default Sum a range of cells based on relative position


Set sCell = Range("B15")
x = Application.WorksheetFunction.Sum(sCell.Offset(0, 2).Resize(1, 4))
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
("List Files" finds files/folders and creates hyperlinked lists)




"DaveO"
wrote in message
...
I have a VBA construct like this one

dim SCell as Range
for each SCell in Selection.Cells
{snip}
next SCell
... where the selected cells are 1 column wide and several rows deep.

As the For... Next spins through the cells in the selected range, I
need to take some actions if the sum of a range of cells on a given
row is greater than zero. So, if SCell is at cell B15, I need to find
out the sum of cells D15:G15.

What is the code to derive that sum? I'm thinking it's some use of
OFFSET, perhaps, but I'm not sure of the syntax. Any ideas?

Thanks,
Dave O