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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Offset vba

Status
Not open for further replies.

end922

Technical User
Apr 17, 2007
59
US
Greetings,

I am trying to add the bottom 3 cells in column C.
Like in C48, i need to know the sum of rows c47,46 and 45.
If I use =sum(offset(reference,rows,cols,[height],[width]))
it ask for a reference cell. I wont always know what that reference cell is. Should I be using a different formula?




Thanks
Eric
 



Hi,

1. Are you formatting a CELL FORMULA or are you just using the spreadsheet SUM function to return a value to your code?

2. Some code for the second option...
Code:
Function SumLastN(n As Integer)
    With ActiveCell
      SumLastN = Application.Sum(Range(Cells(.Row - n, .Column), Cells(.Row - 1, .Column)))
    End With
End Function
this is a user defined function. Paste in a MODULE, not a Sheet Object Code Window.

Use like any other ss function.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
For your reference cell, have a look at the 2 FAQs in this forum that deal with finding the last row of data on a spreadsheet

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top