+ Reply to Thread
Results 1 to 21 of 21

Could you re-write every built-in function in VBA?

  1. #1
    Registered User
    Join Date
    06-16-2016
    Location
    Greece
    MS-Off Ver
    2013
    Posts
    69

    Could you re-write every built-in function in VBA?

    Title. Could you? I've been wondering for a long time...

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Could you re-write every built-in function in VBA?

    no I couldn't - not enough years left in the locker and microsoft keeps adding new functions ...

    and I wouldn't want to use them anyway - UDF would be slower than built-in functions..so why bother....
    Last edited by kev_; 09-10-2017 at 01:18 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    06-16-2016
    Location
    Greece
    MS-Off Ver
    2013
    Posts
    69

    Re: Could you re-write every built-in function in VBA?

    I meant like, theoretically... is there any function that does stuff that can't be replicated by VBA? guess that's the real question :P

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Could you re-write every built-in function in VBA?

    Everything but the IF function, I expect, for its ability to minimally evaluate its arguments.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,844

    Re: Could you re-write every built-in function in VBA?

    Off the top of my head, I cannot think of any of Excel's built in functions that could not be replicated in VBA or other programming language. As kev_ notes, there could be some discussion about whether VBA is a good programming language for performing any of these tasks, but I would be optimistic that the algorithms behind any of Excel's functions could be replicated in VBA.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Could you re-write every built-in function in VBA?

    Theoretically, yes they all could be recreated. VBA's extensible programming allows for using other scripting languages and libraries to expand it capabilities. It would not always yield the most efficient code to perform the task due to so many levels of indirection during execution. Low level langage programming always yields the best in speed but is far more difficult to code in. The programmer ultimately is faced with trade offs between speed, flexibility, and efficiency.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Could you re-write every built-in function in VBA?

    VBA couldn't do the selective argument evaluation that IF does.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Could you re-write every built-in function in VBA?

    VBA could use other scripts to create a praser to solve the issue. It may not be pretty but possible.

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Could you re-write every built-in function in VBA?

    how about a Forum team-building exercise?
    - ask for volunteers to take part in the challenge
    - one volunteer to list all the Excel functions
    - every other volunteer to adopt one Excel function
    - adopted function to be replicated without using any Excel function or VBA function that mimics an Excel function I

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Could you re-write every built-in function in VBA?

    Gosh, that sounds like fun ...

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Could you re-write every built-in function in VBA?

    Quote Originally Posted by shg View Post
    VBA couldn't do the selective argument evaluation that IF does.
    I'm not sure what you mean.
    What values would this return different than Excel's IF.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Could you re-write every built-in function in VBA?

    Watch this evaluate (or not; you know what it does ):

    =IF(SQRT(4)=2, 1, NORM.S.INV(RAND()))

    In VBA, you'll get handed the result of the value-if-false clause. The IF function doesn't bother evaluating it.

  13. #13
    Registered User
    Join Date
    06-16-2016
    Location
    Greece
    MS-Off Ver
    2013
    Posts
    69

    Re: Could you re-write every built-in function in VBA?

    Quote Originally Posted by shg View Post
    VBA couldn't do the selective argument evaluation that IF does.
    wait, why not? Why is excel's IF any different than VBA's? I though I could write it in VBA in 1 minute unless I don't get what you're saying...

    how about a Forum team-building exercise?
    - ask for volunteers to take part in the challenge
    - one volunteer to list all the Excel functions
    - every other volunteer to adopt one Excel function
    - adopted function to be replicated without using any Excel function or VBA function that mimics an Excel function I
    I liked the idea but we'd probably have to narrow it down to some function categories (probably exclude all financial and mathematical functions). after all there's like hundred of functions. Also off the top of my head I literally can't think of any basic function that I can't write in VBA. Then there's functions that it's not clear what they do or what the algorithm is. An example of the former is ENCODEURL I guess. But I suppose it's just a matter of understanding each function. So I guess it would be kind of pointless :p

    In VBA, you'll get handed the result of the value-if-false clause. The IF function doesn't bother evaluating it.
    I suppose you're right but it would still work. I'm not saying that under the scenes Excel functions aren't faster. I'm saying they can probably all be replicated by VBA...

  14. #14
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Could you re-write every built-in function in VBA?

    Quote Originally Posted by shg View Post
    Watch this evaluate (or not; you know what it does ):

    =IF(SQRT(4)=2, 1, NORM.S.INV(RAND()))

    In VBA, you'll get handed the result of the value-if-false clause. The IF function doesn't bother evaluating it.
    with the code in post #11,

    =myIF(mySQRT(4)=2, 1, myNORM.S.INV(myRand())) should return the same results (assuming mySQRT works as SQRT)

  15. #15
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Could you re-write every built-in function in VBA?

    @shg - your enthusiasm is to be applauded.....but....what a mammoth project.........scares me ..... and it was my (very) tongue-in-cheek suggestion.....

  16. #16
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Could you re-write every built-in function in VBA?

    Hey Kev.

    I read post #10 as sarcasm - given away by the "Gosh"
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  17. #17
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Could you re-write every built-in function in VBA?

    @xladept I was taught by my mother that "only the Brits" understand sarcasm...
    Funnily enough "gosh" makes it sound less sarcastic.
    Last edited by kev_; 09-10-2017 at 05:41 PM.

  18. #18
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Could you re-write every built-in function in VBA?

    @ Kev - I read that as sarcasm

  19. #19
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Could you re-write every built-in function in VBA?

    @xladept - that is quite amazing.... "one nation divided by a common language" is clearly no longer true

  20. #20
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Could you re-write every built-in function in VBA?

    Awwww - Gosh

  21. #21
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Could you re-write every built-in function in VBA?

    Quote Originally Posted by mikerickson View Post
    with the code in post #11,

    =myIF(mySQRT(4)=2, 1, myNORM.S.INV(myRand())) should return the same results (assuming mySQRT works as SQRT)
    I wasn't arguing that you can't achieve the same functional result, mike, only that a VBA function can't do its own argument evaluation. I think it was a nice touch by Excel's designers, especially considering that about half of all functions used in Excel are IF.

    Quote Originally Posted by xladept View Post
    @ Kev - I read that as sarcasm
    Bingo.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Built-in-Function checking Array of Zero Length
    By Joakim N in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-17-2014, 04:37 AM
  2. [SOLVED] GCD - subprogram w/o GCD built in Function
    By ChemEBA in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-12-2013, 03:54 PM
  3. Creating Second Derivative Givin a built in function
    By BFlick11 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2010, 08:17 PM
  4. VBA & Built-in function?
    By sanlen in forum Excel General
    Replies: 1
    Last Post: 07-29-2010, 03:40 AM
  5. Code behind Built In function
    By shahper in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-02-2007, 06:08 PM
  6. [SOLVED] Wanted: VB expert to write in built macro in Excel
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2006, 02:20 PM
  7. Now not regonized as a built in Function, in some spreadsheets?
    By Craigm in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-08-2006, 12:35 PM
  8. [SOLVED] Use An Excel Built-In Function Entirely Within VBA
    By MDW in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2006, 06:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1