Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Gracie Hughes   on Mar 04 In MS Office Category.

  
Question Answered By: Reginald Thomas   on Mar 04

To use them, you just type "Worksheetfunction.<name of function>". For
example to use COUNTA in VBA, you would type
"Worksheetfunction.CountA()". If you type "Worksheetfunction." in the
VB Editor you'll get a dropdown list  of the possible functions  you can
call from your VBA code.

Worksheet functions in VBA use the same arguments as the ones on the
worksheet. And keep in mind that if an equivalent VBA function exists,
you will not be able to use that worksheet  function in VBA.

If your problem is long  formulas in your worksheet (which I don't
understand as being a problem), the way you shorten them is by using
defined names.

See for example
www.tushar-mehta.com/.../named_formulas.html

One of your followup posts you mentioned 'I'm not going to rewrite
SUM' -- that is exactly what you are doing.

Function MyQuery(rng as Range, rngtoCheck as Range
MyQuery =
IF(ISNUMBER(VLOOKUP(J8;WebQuery;5;FALSE));VLOOKUP(J8;WebQuery;5;FALSE);0)
End Function

All you are doing is rewriting a built-in function. It's no different
than writing a function like

Function MySum(rng as Variant)
MySum = Worksheetfunction.Sum(rng)
End Function

I understand that in some longer VBA procedures, worksheet functions
might be used for certain calculations. But using VBA solely to insert
worksheet functions will serve no purpose other than to slow down
calculations.

Share: 

 

This Question has 26 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Worksheet functions in VBA Or get search suggestion and latest updates.


Tagged: