View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Vacation's Over Vacation's Over is offline
external usenet poster
 
Posts: 279
Default Sum Dynamic Range - VBA

as written the function would try to overwrie itself with a formula

A function is designed to return something not to do something

last line of function should typically be
RangeTot = 'yourMathHere

Looks to me like you want to use a sub not a function
if you simply replave "function" with "sub"
your code when called will return a formula for totalling from the then
activecell to XLdown

this will be recalculated but the range will not be dynamic on recalculation

If you post what you are trying to do i might be more help

there is a way to sum a dynamic list in XL2003 Help"Excel List"



" wrote:

Can anyone tell me why the end result of this function gives me the
#NAME? error in cell F2?

Function RangeTot()

Dim myLastCell As String
Dim myFirstCell As String

Selection.End(xlDown).Select

myFirstCell = ActiveCell.Address

Selection.End(xlDown).Select

myLastCell = ActiveCell.Address

Range("F2").Select
ActiveCell.FormulaR1C1 = "=sum(myFirstCell" & ":myLastCell" & ")"

End Function

TIA,

Chris