+ Reply to Thread
Results 1 to 10 of 10

Max Func returns Variable name

  1. #1
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Max Func returns Variable name

    This sub below should return a value of 5, how do get this to return variable Five instead?

    Please Login or Register  to view this content.
    Please advice!

    Thank you,

    NTB
    Last edited by NTB; 09-07-2011 at 09:00 AM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,255

    Re: Max Func returns Variable name

    Hi NTB

    Have you looked at the Choose function? No VBA needed. If you really want to put it in VBA you can use Application.WorksheetFunction.Choose...
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Max Func returns Variable name

    MarvinP

    Choose, I have to pick the item specifically...

    I had tried, but the function below return Four... unless I have to put everything in order which in real life the values don't line up like that.

    Any other way that you know?


    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Max Func returns Variable name

    It might help if you explained a little more about what you're trying to do and why - having Excel return a variable name rather than the value in the variable is quite an unusual thing to do.

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Max Func returns Variable name

    hi, NTB, try this out:

    Please Login or Register  to view this content.
    returns value 5
    Last edited by watersev; 09-07-2011 at 02:48 AM.

  6. #6
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Max Func returns Variable name

    Andrew-R:
    Basically, what I posted was a simplified version. I didn't want to confuse everyone too much.
    My function has 8 different variables, 8 different possible directions: Up, Down, Left, Right, UL, UR, DL, DR

    Each variable would hold a dynamic value for each loop and I would ultimately want to pick the variable with the highest value.

    Instead of doing so many if statements, I thought of Max fuction, but Max only returns the highest value but not the variable that holds it.

    Please Login or Register  to view this content.
    To pick DR I would have to do 8 different ifs

    if Up > than the rest then Up
    if Down > the rest the down
    etc etc...

    I would love to have something similiar to

    Please Login or Register  to view this content.
    MaxVar would return "UR" because it holds 6, the highest value
    Last edited by NTB; 09-07-2011 at 07:33 AM.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,255

    Re: Max Func returns Variable name

    Have you looked at the SELECT CASE statement in VBA. It was created for replacing multiple IF statements.
    http://www.ozgrid.com/VBA/select-case.htm or
    http://www.databison.com/index.php/v...ment-in-excel/

  8. #8
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Max Func returns Variable name

    Maybe I'm not understanding this right... but I think it's not relevant to use that here because I would have to compare each variable against the rest.

  9. #9
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Max Func returns Variable name

    OK, how about

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Max Func returns Variable name

    Test run
    Please Login or Register  to view this content.
    Messagebox returns "UR" - DING DING DING.

    Thank you very Much! +1

+ 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