Consulting

Results 1 to 8 of 8

Thread: How to find and use the maximum value in VBA

  1. #1
    VBAX Regular
    Joined
    Sep 2015
    Posts
    48
    Location

    How to find and use the maximum value in VBA

    Hi all,
    I am trying to find and use the maximum value in VBA code. The maximum value is used to select a specific cell. Any help is appreciated. Thanks

  2. #2
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Good morning bbuk9999,

    You could setup a maximum variable and associate the maximum value in a range to that variable for further use.

    Something along the lines of this...

    Sub GetMaxVal() 
        Dim lMax As Long 
        lMax = WorksheetFunction.Max(Range("A:B")) 
    End Sub
    Obviously change the range to suit.

    I hope this helps!
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  3. #3
    VBAX Regular
    Joined
    Sep 2015
    Posts
    48
    Location
    Thanks for your help PAB,
    Can you let me know to do this too use the Max value further? Thanks

  4. #4
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    It depends on what you are trying to do bbuk9999,

    If you have a WorkBook, perhaps you could upload it or post a link to it so we can have a look, obviously take out any sensitive information first.

    I hope this helps!
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  5. #5
    VBAX Regular
    Joined
    Sep 2015
    Posts
    48
    Location
    Thanks PAB, please have a look at the attached file. I am trying to find the maximum value in the attached programme in sheet("Container Yard"), ans in the sheet 2 number 1 should be inserted in as shown in the attached file. by the way , the attached file is dynamic table in VBA. Thanks in advance.
    Attached Files Attached Files

  6. #6
    VBAX Regular
    Joined
    Sep 2015
    Posts
    48
    Location
    How to choose the first maximum value if we have more than one with the same value? Thanks

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Is this for homework or for production? It will make a difference in how I answer.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  8. #8
    VBAX Regular
    Joined
    Jul 2015
    Posts
    66
    Location
    This is for having a knowledge SamT.
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •