+ Reply to Thread
Results 1 to 5 of 5

Use of ROUND() Giving Unexpected Results

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-25-2010
    Location
    Phoenix, Arizona, USA
    MS-Off Ver
    O365
    Posts
    202

    Question Use of ROUND() Giving Unexpected Results

    I have a worksheet that allows the user to place input to cell D4.

    I need to have this value rounded to 1-decimal, so I have the following code on the Worksheet_Change event:

    Formula: copy to clipboard
    Select Case Target.Column
    Case 4
    Select Case Target.Row
    Case 4
    If Target.Value > 0 Then
    Application.EnableEvents = False
    Target.Value = Round(Target.Value, 1)
    Application.EnableEvents = True
    End If
    End Select
    End Select


    When I type 345.45, I would expect the cell value to change to 345.5, BUT it changes to 345.4
    When I type 345.55, I would expect the cell value to change to 345.6, it DOES change to 345.6

    If I use:
    Formula: copy to clipboard
    Select Case Target.Column
    Case 4
    Select Case Target.Row
    Case 4
    If Target.Value > 0 Then
    Application.EnableEvents = False
    Target.Value = Application.WorksheetFunction.Round(Target.Value, 1)
    Application.EnableEvents = True
    End If
    End Select
    End Select


    When I type 345.45, I would expect the cell value to change to 345.5, it DOES change to 345.5
    When I type 345.55, I would expect the cell value to change to 345.6, it DOES change to 345.6


    Why doesn't the first Round() function work as expected?

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Use of ROUND() Giving Unexpected Results

    The VBA version of round uses the "round-to-even" logic; so in this case when the last figure is a 5, it will round to the closest even number, which is what you got in the first example.

  3. #3
    Forum Contributor
    Join Date
    10-25-2010
    Location
    Phoenix, Arizona, USA
    MS-Off Ver
    O365
    Posts
    202

    Re: Use of ROUND() Giving Unexpected Results

    OMG, is that by design? That seems pretty faulty in doing that. I guess I'll use Application.WorksheetFunction.Round, but am still surprised about the need to do so.

    Thanks for confirming my problem and allowing me to understand why it was occurring.

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Use of ROUND() Giving Unexpected Results

    You're welcome, good luck

  5. #5
    Forum Contributor
    Join Date
    10-25-2010
    Location
    Phoenix, Arizona, USA
    MS-Off Ver
    O365
    Posts
    202

    Re: Use of ROUND() Giving Unexpected Results

    Found the following link for this issue.

    https://support.microsoft.com/en-us/kb/194983

    Apparently, when using the ROUND() function for VBA, it uses Banker's rounding.

+ 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. [SOLVED] Complex ??Need to adjust formula giving unexpected results with trim & substitute
    By JEAN1972 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-15-2015, 03:48 AM
  2. [SOLVED] Simple If-Then test giving unexpected results
    By CM1227 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-18-2014, 04:00 PM
  3. Simple If-Then test giving unexpected results
    By CM1227 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2014, 10:18 AM
  4. [SOLVED] Using Index Match or Vlookup giving unexpected results on imported data
    By jacob@thepenpoint in forum Excel General
    Replies: 2
    Last Post: 07-03-2012, 05:49 PM
  5. Formula giving unexpected results
    By johnmerlino in forum Excel General
    Replies: 6
    Last Post: 12-01-2010, 01:20 AM
  6. Autofilter giving unexpected results!
    By Colin Vicary in forum Excel General
    Replies: 3
    Last Post: 09-28-2006, 07:20 AM
  7. Equation giving unexpected results
    By Mike K in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-27-2005, 11:06 AM

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