Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 40
Default Using a worksheet function from VBA

I'm a bit confused as to how to use obtain, in VBA, the value which would be
returned by a worksheet function. On one of my sheets, in column 2, there is
a list of numbers. Suppose I wanted to know the highest value in this column
between rows 7 and 707 inclusive. I could obtain this by

Max (B7:B707)

Now suppose I ws in a VBA module and wanted this value. Can anyone tell me
what code statement(s) would allow me to put this value into variable. I
vaguely remember that this calls for the "application." syntax, but I have
tried to find the specifics and am stymied. Any help would be greatly
appreciated.


--
-regards
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,069
Default Using a worksheet function from VBA

You are referring to Application.WorksheetFunction. Here is the example from
Excel Help:

Set myRange = Worksheets("Sheet1").Range("A1:C10")
answer = Application.WorksheetFunction.Min(myRange)
MsgBox answer

Here is an example from a project I worked on:

Elem$ = vbNullString
Elem$ = Application.WorksheetFunction.VLookup(Me.cboCO_Exp Type.Value, _
ThisWorkbook.Sheets(CostLogicSht$).Columns("B:E"), 4, False)
If Elem$ < "" Then
Me.txtCO_CostElem.Value = Elem$
End If

Not all worksheet functions can be used with Application.WorksheetFunction.
See Excel Help for a list.

Hope this helps,

Hutch

"GeorgeJ" wrote:

I'm a bit confused as to how to use obtain, in VBA, the value which would be
returned by a worksheet function. On one of my sheets, in column 2, there is
a list of numbers. Suppose I wanted to know the highest value in this column
between rows 7 and 707 inclusive. I could obtain this by

Max (B7:B707)

Now suppose I ws in a VBA module and wanted this value. Can anyone tell me
what code statement(s) would allow me to put this value into variable. I
vaguely remember that this calls for the "application." syntax, but I have
tried to find the specifics and am stymied. Any help would be greatly
appreciated.


--
-regards

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 40
Default Using a worksheet function from VBA


Tom, your post was just what the doctor ordered. I couldn't remember the
method "application.worksheetfunction", but as soon as I saw your post it
came back to me. Your example was helpful too. and your response was as
prompt as it was helpful. I don't know what I'd do without this forum.

-Regards
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 524
Default Using a worksheet function from VBA

Why not just use [...] or Evaluate("...") ? What am I missing?

Thu, 2 Aug 2007 14:52:03 -0700 from Tom Hutchins
:
You are referring to Application.WorksheetFunction. Here is the example from
Excel Help:

Set myRange = Worksheets("Sheet1").Range("A1:C10")
answer = Application.WorksheetFunction.Min(myRange)
MsgBox answer

Here is an example from a project I worked on:

Elem$ = vbNullString
Elem$ = Application.WorksheetFunction.VLookup(Me.cboCO_Exp Type.Value, _
ThisWorkbook.Sheets(CostLogicSht$).Columns("B:E"), 4, False)
If Elem$ < "" Then
Me.txtCO_CostElem.Value = Elem$
End If

Not all worksheet functions can be used with Application.WorksheetFunction.
See Excel Help for a list.

Hope this helps,

Hutch

"GeorgeJ" wrote:

I'm a bit confused as to how to use obtain, in VBA, the value which would be
returned by a worksheet function. On one of my sheets, in column 2, there is
a list of numbers. Suppose I wanted to know the highest value in this column
between rows 7 and 707 inclusive. I could obtain this by

Max (B7:B707)

Now suppose I ws in a VBA module and wanted this value. Can anyone tell me
what code statement(s) would allow me to put this value into variable. I
vaguely remember that this calls for the "application." syntax, but I have
tried to find the specifics and am stymied. Any help would be greatly
appreciated.


--
-regards



--
"The Internet is famously powered by the twin engines of
bitterness and contempt." -- Nathan Rabin, /The Onion/
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
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
Which worksheet function would I use? plunk25 Excel Worksheet Functions 4 October 13th 06 06:17 PM
WorkSheet Function Help Dawn Excel Worksheet Functions 0 February 6th 06 09:33 PM
Is there a worksheet function that will... Adam Kroger Excel Worksheet Functions 1 November 20th 05 07:41 PM
Reference the worksheet from a multiple worksheet range function ( DBickel Excel Worksheet Functions 1 May 28th 05 03:49 AM
Can the offset worksheet function reference another worksheet AlistairJ Excel Worksheet Functions 2 May 9th 05 06:18 PM


All times are GMT +1. The time now is 11:05 AM.

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"