+ Reply to Thread
Results 1 to 15 of 15

Finding Max value in one row of a 2D array (array is not pulled from sheet)

  1. #1
    Registered User
    Join Date
    05-24-2011
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    27

    Finding Max value in one row of a 2D array (array is not pulled from sheet)

    What I'm trying to do is generate a 2D array of values in VBA from data in a spreadsheet. (I know how to generate 2D arrays and don't need help with that.)

    What I would like to do next is look at each row or column of the 2D array and find the max value. I've tried using the worksheetfunction.MAX to no avail. Any help would be greatly appreciated.

  2. #2
    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: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Hello marrott2,

    Here is an example of how to get the max value of either an entire row or column of an array. The advantage of Application over WorksheetFunction is Application will not throw an error. It will return an error value instead. You can for an error by using the IsError() statement in VBA.
    Please Login or Register  to view this content.
    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!)

  3. #3
    Registered User
    Join Date
    05-24-2011
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    27

    Re: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Works like a charm. Thanks for the quick help. I guess I need to brush up on my indexing functions.

  4. #4
    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: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Hello marrott2,

    You're welcome. Glad that it worked on the Mac. I wasn't sure it would.

  5. #5
    Registered User
    Join Date
    05-24-2011
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    27

    Re: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    I have Office for Mac 2011, so almost all of the functionality of VBA works like usual.

  6. #6
    Registered User
    Join Date
    05-24-2011
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    27

    Re: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Any idea how to possibly get the location of the max value in an row/column in an array?

  7. #7
    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: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Hello marrott2,

    The keyword is almost.

  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: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Hello marrott2,

    Try this...
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-24-2011
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    27

    Re: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Quote Originally Posted by Leith Ross View Post
    Try this...
    Please Login or Register  to view this content.
    Tried that already but won't return a location within the array

  10. #10
    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: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Hello marrott2,

    Sorry, Loc is a reserved word. Try this...
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-24-2011
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    27

    Re: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Leith,

    I knew Loc was reserved and didn't use it. Still not getting it to work. It is coming up with a mismatch error 2042 when I try and print to a msgbox or #N/A when I print to spreadsheet.

  12. #12
    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: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Hello marrott2,

    Error 2042 is the Excel #N/A error. It seems that there was no match found in the array. The example works fine in Windows. It returns a 2 for the second element in the array.

  13. #13
    Registered User
    Join Date
    05-24-2011
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    27

    Re: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Leith,

    Figured out my problem
    Please Login or Register  to view this content.
    I needed to define the range to search in the Match function as the particular row or column where the max was located not the entire array.

  14. #14
    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: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    Hello marrott2,

    Excellent! (There was much rejoicing as they ate Robin's minstrels.)

  15. #15
    Registered User
    Join Date
    05-24-2011
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    27

    Re: Finding Max value in one row of a 2D array (array is not pulled from sheet)

    * and there was much rejoicing..... yaaayyyyyy

    Thanks again.

+ 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. Finding Values Contained in an Array in a Sheet
    By sperry2565 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-26-2013, 04:33 PM
  2. [SOLVED] Quick Array question - Copy array to another array then resize?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2013, 01:17 AM
  3. Assign sheet value to array... and redim the array size
    By Orange.CL in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-27-2010, 07:18 AM
  4. Function to list data pulled from 2-D Array
    By nscottwerner in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-19-2009, 06:08 PM
  5. Selection to Array and Array to Sheet
    By qpg in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-14-2006, 01:00 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