+ Reply to Thread
Results 1 to 12 of 12

VBA vs Built-In Functions

  1. #1
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    VBA vs Built-In Functions

    I know this has been beaten like drug user owing a lot of money to a thug but the whole built in function vs using VBA often beckons me to question it. From a thread, FDibbins provided
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Now I know that a lot of you guys and gals here have no problem seeing something like that and think, "there's nothing tough about that" but when I see stuff like that my eyes invert. I know it's probably due to my lack of using built in functions because I've been on the VBA wagon right out of the gates (as far as Excel goes). Maybe I should spend some time with the functions but at this point in my career with Excel I almost feel I can write a code block quicker than coming up with what you may find a simple solution sheet side.

    There's no real point to this other than what I've just stated so....look a bunny!
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA vs Built-In Functions

    I'm just the opposite, I learned formulas first and VBA later, so I almost always try for a non-VBA solution (formulas, built-in functionality like text-to-columns or filters) first.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: VBA vs Built-In Functions

    I guess I should expand myself more with this and perhaps look into the general forums a little more than I do (which is almost never). They seem like such a learning curve though and that's why I've kept away from them. I can Sum() like the best of you gurus though

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: VBA vs Built-In Functions

    I think my knowledge of Excel and of VBA developed in parallel, partly ... Ok, in a large part, due to asking, answering and observing questions in these forums.

    I would generally opt for a built in function solution over a VBA solution if there is one. Admittedly, some of the functions knocked out by the experts here don't always spring to mind.

    Probably the only exception that I might make is complex and widespread array functions in which case a VBA solution may be preferable for performance reasons.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: VBA vs Built-In Functions

    As you know my VBA skills are limited...but even that i believe that i can give formulas solutions to more than 80%(from rest 20% some of these needs VBA(can not do using formulas) and some just i don't know how to do..) of Excel cases, some times these are inapplicable for some reasons..Very slow...too many repeated calulations(Array formulas)...complicated for understanding..etc...

    So in my own projects i usually prefer to ask for help from the VBA experts here to built these.

    I like VBA and i'll try to learn it!
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: VBA vs Built-In Functions

    Here's an example:

    Find value in range, loop for each row


    Over 10,000 rows the formula and the code both complete within 2 seconds. The formula is marginally faster.

    Over 100,000 rows the formula takes 3.6 seconds and the code takes 2min18 seconds
    Over 200,000 rows the formula takes 9.9 seconds and the code takes 4min47 seconds

    Just sayin' ...

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: VBA vs Built-In Functions

    Hi TMS, I guess my issue is that I can't readily look at a function, even the one from the thread you linked to, and easily know what it is trying to accomplish. Because of this, I can't readily create a function either.

    I think I'm going to have to make it my goal to break on through to that evil side of Excel

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: VBA vs Built-In Functions

    And, to be fair, I still see a lot of formulas presented here and it's as though a black mist comes down in front of my eyes ...

  9. #9
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: VBA vs Built-In Functions

    I believe the original formula,

    =IF(ISERROR(VLOOKUP(A2,$E$1:$F$10,2,1)),B2,VLOOKUP(A2,$E$1:$F$10,2,1))

    can now simply be:

    =IFERROR(VLOOKUP(A2,$E$1:$F$10,2,1),B2)

    Even less typing! It's a good time to get into formulas! (Ok, since 2007, when IFERROR came along.)

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

    Re: VBA vs Built-In Functions

    I think a spreadsheet full of formulas is very fragile.

    Concerning the example posted by TMShucks, did snb's code get a trial?

    I suspect that that ran quite handily.
    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

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,944

    Re: VBA vs Built-In Functions

    @ Paul, If I remember correctly, the OP was using 2003, hence no iferror()

    In support of my use of formulas over VBA...my VBA sucks lol
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  12. #12
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA vs Built-In Functions

    How do you time a worksheet function?
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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