LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Create Function using Excel VBA

This seemed to work ok:

Option Explicit
Function MinPrice(ParamArray arglist() As Variant) As Variant 'text or number
Dim arg As Variant
Dim FoundANumber As Boolean
Dim myMin As Double

myMin = 100 ^ 100 'some really big number
FoundANumber = False
For Each arg In arglist
If IsNumeric(arg) Then
FoundANumber = True
myMin = WorksheetFunction.Min(myMin, arg)
End If
Next arg

If FoundANumber = True Then
MinPrice = myMin
Else
MinPrice = "Item Not Bid"
End If
End Function
Sub aa()
MsgBox MinPrice("a", 3, CVErr(xlErrNA))
End Sub

But maybe you could use an array formula:

=IF(COUNT(A1:A10)=0,"Item Not Bid",MIN(IF(ISNUMBER(A1:A10),A1:A10)))

This is an array formula. Hit ctrl-shift-enter instead of enter. If you do it
correctly, excel will wrap curly brackets {} around your formula. (don't type
them yourself.)


Bob K wrote:

I am trying to create a function that looks at each argument and does
validation of the argument to determine whether or not to include the
argument in the min function. The validation process should exclude
arguments that:

Argument = 0
Argument is text
Argument is an error

If the all the arguments fail the validation, it should return a text
message ie €śItem not bid€ť otherwise it should return the result of the min
value of the arguments that pass the validation process. Any help would be
much appreciated. I also want to create a function the works similar using
€śSmall€ť.

Thanks,

bob

Function MinPrice(ParamArray arglist() As Variant) As Double
For Each arg In arglist
MinPrice = WorksheetFunction.Min(arglist)
Next arg
End Function


--

Dave Peterson
 
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
Create VBA function (UDF) in Excel 2003 Hershmab Excel Discussion (Misc queries) 2 November 30th 09 09:48 AM
How do I create and save a new function in Excel? Sandals Excel Worksheet Functions 1 October 10th 08 02:04 PM
create a discount function in excel number Excel Programming 5 July 7th 05 08:13 PM
How do I create a ratio function in Excel? Michele Excel Worksheet Functions 2 May 24th 05 05:47 PM
How to create User Defined function in Excel Johnny Ko Excel Programming 2 December 5th 03 09:09 AM


All times are GMT +1. The time now is 09:39 PM.

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

About Us

"It's about Microsoft Excel"