Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default WorksheetFunction

Stuart,

The primary difference between using or not using WorksheetFunction is how
errors are handled. When you use WorksheetFunction and an error occurs, a
trappable error is raised by VBA. For example,

Dim V As Variant
V = Application.WorksheetFunction.Sum(1, "A", 3)

will raise an error 1004, and this can be trapped by an On Error statement.

When you do not use WorksheetFunction, the result of the function is a error
typed variant , but code does not stop executing and no trappable error is
raised. For example,

Dim V As Variant
V = Application.Sum(1, "A", 3)
Debug.Print V

(Note that if V is declared as a numeric type, you'll get an error 13, type
mismatch, because VBA can't put an error typed value in a numeric variable.)

Whether you do or do not use WorksheetFunction is a matter of personal
coding style. I tend to use it because I rarely use the Variant variable
type, and I like the intellisense support when typing.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Stuart" wrote in message
...
I have noticed in the advice given on this grouop that when a
worksheetfunction is used the syntax is to include
"Application.Worksheetfunction" before the relative function. For along

time
now I have utilised worksheet functions by simply adding "application"
before the function. What are the benifits in using the longer statement?


Stuart




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default WorksheetFunction

I have noticed in the advice given on this grouop that when a
worksheetfunction is used the syntax is to include
"Application.Worksheetfunction" before the relative function. For along time
now I have utilised worksheet functions by simply adding "application"
before the function. What are the benifits in using the longer statement?


Stuart


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default WorksheetFunction

Many thanks for your detailed answer, definately another string added to my
bow!

stuart


Chip Pearson wrote in message
...
Stuart,

The primary difference between using or not using WorksheetFunction is how
errors are handled. When you use WorksheetFunction and an error occurs, a
trappable error is raised by VBA. For example,

Dim V As Variant
V = Application.WorksheetFunction.Sum(1, "A", 3)

will raise an error 1004, and this can be trapped by an On Error

statement.

When you do not use WorksheetFunction, the result of the function is a

error
typed variant , but code does not stop executing and no trappable error is
raised. For example,

Dim V As Variant
V = Application.Sum(1, "A", 3)
Debug.Print V

(Note that if V is declared as a numeric type, you'll get an error 13,

type
mismatch, because VBA can't put an error typed value in a numeric

variable.)

Whether you do or do not use WorksheetFunction is a matter of personal
coding style. I tend to use it because I rarely use the Variant variable
type, and I like the intellisense support when typing.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Stuart" wrote in message
...
I have noticed in the advice given on this grouop that when a
worksheetfunction is used the syntax is to include
"Application.Worksheetfunction" before the relative function. For along

time
now I have utilised worksheet functions by simply adding "application"
before the function. What are the benifits in using the longer

statement?


Stuart






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
WorksheetFunction help Ayo Excel Discussion (Misc queries) 2 July 20th 08 10:48 PM
Can't use WorksheetFunction Yossi Excel Discussion (Misc queries) 5 January 25th 06 10:07 PM
WorksheetFunction with VBA Ghislain Marcotte Excel Discussion (Misc queries) 2 February 13th 05 07:08 AM
worksheetFunction isblank tazgore Excel Programming 1 November 10th 03 10:39 PM
worksheetfunction devnext Excel Programming 1 October 29th 03 12:48 PM


All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"