+ Reply to Thread
Results 1 to 7 of 7

Finding the Highest value among a set of numbers

  1. #1
    Registered User
    Join Date
    11-08-2006
    Posts
    41

    Finding the Highest value among a set of numbers

    Hello everybody!

    I am struggling with an official task, which mainly relies on the Macros.
    As I have mentioned in my first query, I am a beginner in Excel and this is the second query.

    I have 10 variables bearing 10 different values. I want to find the highest values of them.
    I could not find any function like MAX etc. Neither I could put these variables in an array and Sort them in descending order - I could not make out how to define an array and sort it etc.
    (How to work with Arrays in VBA will be an additional tip, if possible).

    Regards,

  2. #2
    Registered User
    Join Date
    08-16-2007
    Location
    Portsmouth, UK
    Posts
    86
    Hi, you said you could not find any function like MAX, but you can use all the worksheet functions in VBA providing that VBA doesn't have it's own equivalent. just type:

    Please Login or Register  to view this content.
    Obviously change the range to suit. that is of course providing that your values are in a worksheet.

    As far as the arrays go, afraid I can't help, although I'm sure I have seen posts on here that deal with sorting arrays.

    Regards

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    sorting arrays

    This could be a start:-
    Code (1) first loop through the range of cell to initialise all the variables. (The variables are 10 different numbers in Range ("A1:A10")) NB:- You could skip this first bit if you want to assign your variables in a different way It then loops through the Array, by setting the first number as Max and then, if the next number in array is larger than the previous then that becomes the Max .
    Please Login or Register  to view this content.
    You can also set the Array as a single Variant, variable as shown in the second bit of code, and then use the Worksheetfunction.Max.
    NB:- Variant arrays always have two Indices as shown
    Please Login or Register  to view this content.
    I hope this helps
    Mick

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

    If they are scattered in various cells, this is one way to fill an array with those values.
    Please Login or Register  to view this content.
    Application.Max also works on arrays, so sorting is not needed to find the Max value.
    Please Login or Register  to view this content.
    If there are other reasons for sorting an array, this bubble sort routine will do it.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-08-2006
    Posts
    41
    Great help. All the friends put valuable info, especially on Arrays, into my knowledge.

    As I had mentioned that I have different values in 10 variables; like JanAmnt, FebAmnt etc. I like to know, how can I find the highest value in one of these variables.

    I would be able to use this feature in a number of other places, in my code.

    Thanks in anticipation and regards.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    try
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-08-2006
    Posts
    41
    Great. Salute to all the wizards. Wish you the best time.

    Best regards.

+ 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