why doesn't vba have a min/max function?

MetLife

Board Regular
Joined
Jul 2, 2012
Messages
241
I just wrote a min function:

Function Min(a, b)
If a < b Then
Min = a
Else
Min = b
End If
End Function

Why can't microsoft add this?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,078
Office Version
365
Platform
Windows
Why not just use the worksheetfunction?
 

MetLife

Board Regular
Joined
Jul 2, 2012
Messages
241
It slows down the program. Never use worksheet functions.

I blame microsoft. This is why people are using python instead of excel.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,504
Office Version
2010
Platform
Windows
It slows down the program. Never use worksheet functions.

I blame microsoft. This is why people are using python instead of excel.
Fluff meant for you to use the WorksheetFunction object which, as far as I know, is not all that slow (I use it all the time when I need Excel functionality that is not natively provided by VBA). In case you are not familiar with this object, you would call it like this...

WorksheetFunction.Min(...arg list...)

WorksheetFunction.Max(...arg list...)
 

MetLife

Board Regular
Joined
Jul 2, 2012
Messages
241
Fluff meant for you to use the WorksheetFunction object which, as far as I know, is not all that slow (I use it all the time when I need Excel functionality that is not natively provided by VBA). In case you are not familiar with this object, you would call it like this...

WorksheetFunction.Min(...arg list...)

WorksheetFunction.Max(...arg list...)
OK - I didn't know that.

I was always told that using worksheet functions was a big no no.

Thanks!
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,362
Office Version
365
Platform
Windows
A big no no where/when exactly?
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
11,471
Office Version
365, 2010
Platform
Windows, Mobile
Read this on my mobile at work and was confused as to why it was stated that WorkSheetFunction was slow and so after getting home dug out an old laptop and done a randbetween 1,400000 over 200000 rows and got FastExcel to time running the code below

Code:
Sub testmax()
Dim X As Long
X = Application.WorksheetFunction.Max(Range("A1:A200000"))
Debug.Print X
End Sub
The result was 7.43 milliseconds, that seems reasonably fast to me.
 

Forum statistics

Threads
1,081,702
Messages
5,360,743
Members
400,595
Latest member
T_Dubs

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top