Reuse Application.WorksheetFunction

  • Thread starter Thread starter jlclyde
  • Start date Start date
J

jlclyde

Is there a way to reuse the Application.WorksheetFunction?
For instance there are several times in the macro that I am writting
that I would like to do Application.worksheetfunction.SUM(XXXXX). It
woudl be nice if I could do Fn.Sum(XXXXX) or Fn.SUMIF(XXXXXXX)

Thanks,
Jay
 
Use your own UDF:

Function zum(r As Range) As Variant
zum = Application.WorksheetFunction.Sum(r)
End Function

Sub main()
Dim r As Range
Set r = Range("A1:A10")
x = zum(r)
MsgBox (x)
End Sub

once you have defined zum(), you can re-use it over and over.
 
Use your own UDF:

Function zum(r As Range) As Variant
zum = Application.WorksheetFunction.Sum(r)
End Function

Sub main()
Dim r As Range
Set r = Range("A1:A10")
x = zum(r)
MsgBox (x)
End Sub

once you have defined zum(), you can re-use it over and over.
--
Gary''s Student - gsnu2007L






- Show quoted text -

I need to change the function often. I am lookign for a way to reuse
the Application.WorksheetFunction section. Or turn it into Fn, so
that I only have to type Fn.Sum(XXX) or Fn.CountA(XXXX).
Thanks,
Jay
 
Dim Fn As WorksheetFunction
Set Fn = Application.WorksheetFunction
MsgBox Fn.Sum(Range("A:a"))
 
Dim Fn As WorksheetFunction
Set Fn = Application.WorksheetFunction
MsgBox Fn.Sum(Range("A:a"))







--

Dave Peterson- Hide quoted text -

- Show quoted text -

Thanks this works exactly like I had hoped it would.

Jay
 
Back
Top