+ Reply to Thread
Results 1 to 4 of 4

User Defined Function: Nested Ifs?

  1. #1
    Registered User
    Join Date
    09-06-2010
    Location
    Indianapolis
    MS-Off Ver
    Excel 2007
    Posts
    2

    User Defined Function: Nested Ifs?

    I'm created a User Defined Function that looks up and applies the correct tax bracket based on certain inputs. I'm quit new to the user defined function/VBA world but and pretty excited to figure this stuff out. In essence, I'm just trying to embed a dozen vlookup tables in the code, and have the correct one chosen based on choosing the right arguments.

    Here's what I have

    Please Login or Register  to view this content.
    Last edited by indianagreg; 09-06-2010 at 09:27 PM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: User Defined Function: Nested Ifs?

    Hello indianagreg,

    I wouldn't do this with a UDF at all, not touching VBA, even. This gets way too complex and hard to maintain. Look at how you have errors in your data already in the sample you posted.

    Please Login or Register  to view this content.
    Shouldn't the numbers both be the same, either 8376 or 9376?

    Anyway, this is done much easier and with a lot less typing by creating a few lookup tables and a handful of formulas. See attached. I changed the values from status to status, so you can see that the lookups work. Plug in your own numbers and see.

    Other factors for the calculation can easily be added, a few more rows in the lookup table for another parameter, another Index/Match function to look up the value.

    With VBA you would be writing pages and pages of code again.

    cheers,
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: User Defined Function: Nested Ifs?

    the function appears to be ok

    see the function(with dim statements) and a sub for using function
    the result will be in A1 of the active sheet. manually check whether it is ok

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    Re: User Defined Function: Nested Ifs?

    I'm not sure what you're asking exactly. But, you may want to consider a Select Case structure. Might be easier to maintain. I calculate the bracket in the beginning and go from there...

    Please Login or Register  to view this content.

+ 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