+ Reply to Thread
Results 1 to 6 of 6

Finding Max of multiple cells and assigning the value to a variable

  1. #1
    Registered User
    Join Date
    11-15-2009
    Location
    ~1 AU from the Sun
    MS-Off Ver
    Excel 2007
    Posts
    5

    Finding Max of multiple cells and assigning the value to a variable

    Hello!

    I have experience writing Macros for Excel, but I cannot seem to figure out how to perform an operation. I hope that someone here will be more familiar with the syntax and passing of parameters to help.

    I have two nonadjacent columns; C and F. I would like to find the maximum of two cells in the same row and assign the value to another cell (same row) in J; up to a certain row.

    For example:

    ____C____ F____ J
    1|__0____ 5____ 5
    2|__10___ 9____ 10
    3|__1____Null___1
    4|__Null__63____63

    What I have so far is something along the lines of:

    Please Login or Register  to view this content.
    I could do this with a few IF statements, but my goal is to do it in a single line. I don't see why it couldn't be done. I just think my syntax for passing the Value parameter to the Max function is incorrect. Nor do I believe that I am calling the Max function properly.

    *The reason for not simply typing in a formula into the cells as "=Max(C1,F1)" is because I have around 500 rows of data, not every single row has data, i.e. C and F may both be Null, and I will be using this to perform another function to assign a different value to J later on.
    Last edited by DonkeyOte; 11-16-2009 at 04:22 AM.

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

    Re: Finding Max of multiple cells and assigning the value to a variable

    The WorksheetFuction property of the Application object is what you need.
    Please Login or Register  to view this content.
    or
    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.

  3. #3
    Registered User
    Join Date
    11-15-2009
    Location
    ~1 AU from the Sun
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Finding Max of multiple cells and assigning the value to a variable

    Wow, I wasn't as far off as I thought. Thank you very much for your help! Do you know of any online resources that explain what Application in "Application.Max" is and what WorksheetFunction's are available? I am familiar with the basics of programming, just not the calling of functions, Excel ojbects, and their properties.

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

    Re: Finding Max of multiple cells and assigning the value to a variable

    I'd start with the VBEditior Help system.
    The Object Browser is a great, great help. Note that it takes a bit of practice to understand what the Object Browser is saying and how to use all its features.

  5. #5
    Registered User
    Join Date
    11-15-2009
    Location
    ~1 AU from the Sun
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Finding Max of multiple cells and assigning the value to a variable

    Noted. Thank you very much for your time.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Finding Max of multiple cells and assigning the value to a variable

    t3chn0babbl3, welcome to the board, going forward please ensure you wrap your VBA in code tags per forum requirements - I have on this occasion edited your initial post for you.

+ 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