+ Reply to Thread
Results 1 to 10 of 10

Capturing highest value on each row

  1. #1
    Registered User
    Join Date
    06-27-2017
    Location
    Australia
    MS-Off Ver
    2015
    Posts
    6

    Capturing highest value on each row

    Hi All,

    Have been using this forum and highly value the contributors for some time now, I am quite proficient at excel but VBA is a whole other kettle of fish.

    So thank for all of the vicarious help to date, but I have a problem with hopefully an easy fix, the following piece of code does exactly what I need it to, but i need to find a way to continue the code to subsequent rows e.g.;
    source_range = "f32"
    target_range = "h32"

    Here is the code;

    Private Sub Worksheet_Change(ByVal Target As Range)

    Const sSOURCE_RANGE = "F32"
    Const sTARGET_RANGE = "H32"

    Application.EnableEvents = False

    If Not Application.Intersect(Target, Range(sSOURCE_RANGE)) Is Nothing Then
    If Range(sSOURCE_RANGE).Value > Range(sTARGET_RANGE).Value Then
    Range(sTARGET_RANGE).Value = Range(sSOURCE_RANGE).Value
    End If
    End If

    Application.EnableEvents = True

    End Sub

    I am using this in a worksheet to track highest losses and give me a warning, this is how it looks with the 3.90 value the result of the existing code, i need it to work from rows 32 to 64
    A2M 750 $2,435.01 $3.247 $3.805 HOLD 3.90 $2,853.75 $418.74 17.20% #NAME?
    ANL 54,054 $2,019.95 $0.037 $0.044 HOLD $2,378.38 $358.43 17.74% #NAME?

    Any help or advice would be much appreciated and thanks in advance

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Capturing highest value on each row

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    06-27-2017
    Location
    Australia
    MS-Off Ver
    2015
    Posts
    6

    Re: Capturing highest value on each row

    Quote Originally Posted by AlphaFrog View Post
    Please Login or Register  to view this content.
    Thanks so much for that, you are awesome, this has been bending my brain for some time now

  4. #4
    Registered User
    Join Date
    06-27-2017
    Location
    Australia
    MS-Off Ver
    2015
    Posts
    6

    Re: Capturing highest value on each row

    Thanks again AlphaFrog,

    Is there any reason the formula would be rounding up, if I change the (, 2) to (, 3) will it give me three decimal places thanks?

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,338

    Re: Capturing highest value on each row

    Offset has nothing to do with rounding up.
    To round to 3 decimal places change the line to

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    06-27-2017
    Location
    Australia
    MS-Off Ver
    2015
    Posts
    6

    Re: Capturing highest value on each row

    Quote Originally Posted by bakerman2 View Post
    Offset has nothing to do with rounding up.
    To round to 3 decimal places change the line to

    Please Login or Register  to view this content.
    Hi Bakerman, thanks for the input I tried and it didn't quite work, still rounding at 2 places, I tried to alter the if target.value section as well and that broke the code, so looks like this one is still up in the air, if you have any more suggestions it would be much appreciated thanks.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,338

    Re: Capturing highest value on each row

    How about this.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-27-2017
    Location
    Australia
    MS-Off Ver
    2015
    Posts
    6

    Re: Capturing highest value on each row

    Quote Originally Posted by bakerman2 View Post
    How about this.

    Please Login or Register  to view this content.
    Thanks again, this is now doing some strange things. All through this I have made sure I have my column formatted to currency with three decimal places, but this now seems to be dropping the format, so every time I format the row, the equation result takes the formatting with the new code.

    I tried the original code and that is also doing the same rounding, which seems to be set at one decimal place across all three variants.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Capturing highest value on each row

    Don't forget that Round in VBA uses bankers' rounding unlike the ROUND worksheet function. If you want the same behaviour as the worksheet function, you need to use
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  10. #10
    Registered User
    Join Date
    06-27-2017
    Location
    Australia
    MS-Off Ver
    2015
    Posts
    6

    Re: Capturing highest value on each row

    Quote Originally Posted by xlnitwit View Post
    Don't forget that Round in VBA uses bankers' rounding unlike the ROUND worksheet function. If you want the same behaviour as the worksheet function, you need to use
    Please Login or Register  to view this content.
    Signed sealed and delivered, that has solved my issue, thanks to all of you, you have helped save me hours of pain and suffering, much appreciated!

+ 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. Replies: 3
    Last Post: 06-09-2016, 12:51 PM
  2. [SOLVED] Need to select earliest five rows matching highest value, and next highest if not enough
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-05-2016, 11:26 AM
  3. [SOLVED] Max formula to return total of highest, second highest and third highest value
    By JonWilf in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-06-2016, 08:20 AM
  4. How to change the lowest to highest into Highest to lowes ??
    By jasond1992 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2015, 03:38 AM
  5. [SOLVED] Capturing highest value of offset
    By daffodil11 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-13-2014, 02:49 PM
  6. VBA code to find highest and 2nd highest number based in criteria
    By Michael007 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-25-2011, 08:38 AM
  7. Replies: 3
    Last Post: 08-10-2006, 11:40 PM

Tags for this Thread

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