Negating a value results in only approximate negative

I've run into a somewhat confusing situation.
The following short and simple VBA macros was added to an existing large VBA project that I created: the project works well.
I've managed to make this code work, but I can't figure why the 'commented' line does NOT do the job.
The code is designed to take the value from a cell in the worksheet and place the exact negative of that value in the empty cell immediately below. The cell below will, by design, be empty and available for the negated value. All values in the spreadsheet
will have been entered as dollar and cents values [i.e.  49.66, 20.00 etc.] Simply negating a value such as 49.66 will show up in the spreadsheet as -49.66 (cells are formatted as currency) but the actual value will be something like 49.6599322 etc. While
this is not a serious problem... the values appear correctly in the sheet, I would not want to sum the values since the net sum will NOT be zero. [These will in effect be a number of these reversals in a column along with various other values].
The code for the routine is as follows:
Sub Neg_Amt()
' Neg_Amt Macro'
' Keyboard Shortcut: Ctrl+n
' Reverses the value of the cell... cell below must be empty
Dim r, c As Integer
Dim x As Single
x = 0
r = ActiveCell.Cells.Row
c = ActiveCell.Cells.Column
x = ActiveCell.Value
Cells(r + 1, c).Value = -ActiveCell.Value       'use this approach rather than -x, gives exact value whereas -x seems to be not
' '   Cells(r + 1, c).Value = -x                       'commented out   ... this is the problem line yielding unexpected
results    
End
End Sub
If anyone could explain why the simpler approach x= -x does not work, I would appreciate your help.
Thanks  IAFxl

Have a look at the following url. Quite a good explanation.
http://stackoverflow.com/questions/12680609/excel-2007-vba-calculations-wrong
Also try Dim x as Currency      I understand that this is designed to alleviate the problem. In the following example at the above URL it works if you change it to Currency.
Example edited since initial post.
Sub test()
Dim me_wrong As Double
me_wrong = 1000 - 999.59
MsgBox me_wrong
Dim me_correct As Currency
me_correct = 1000 - 999.59
MsgBox me_correct
End Sub
Regards, OssieMac

Similar Messages

  • How to hide value "result" on chararcteristic?

    Hi,
    When I am running Ad Hoc report on ODS I get in the first row result calculating all rows.
    With key figures it's okey, because i get summation of all rows, but with characteristics I get value "RESULT".
    I want to see only value for summation and where the characteristics are I don't want to see value "RESULT".
    I can only get that if I put key figure in the last column, but I want to put it somewhere in the middle.
    Any ideas?
    Regards,
    Uros

    Hi
    In query designer -> Go to change query ->Go to characteristic-> right mouse click-> properties ->Supress result rows -> Here select always.
    Do this for all characteristics except the first characteristic (top most in ROws section), otherwise you will not get Result at all.
    Hope this helps
    Regards
    Pradip

  • How can I multiply all values of a 4-element array with all of its inverse values resulting to an array having all 16 products?

    I'm quite new to LabVIEW (v.8.0) and I'm trying to figure out the easiest way to have a 4-element array multiplied by its inverse values resulting in a 16-element array
    Array 1 values = 1, 2, 3, 4
    Array 1 inverse values = 1, 0.5, 0.33, 0.25
    Resulting array = (1, 0.5, 0.33, 0.25, 2, 1, 0.66, 0.5, 3, 1.5, 1, 0.75, 4, 2, 1.32, 1)
    Any advice would be appreciated. Thanks!
    Solved!
    Go to Solution.

    Attachments:
    mo.doc ‏27 KB

  • How can I make a row of cells containing 3-digit decimals, who's values resulted from calculations within the spreadsheet, appear as durations of minutes and seconds?

    Row 6 in this spreadsheet is the result of Row 2/Row 3 as evidenced by the formula listed while Cell Y6 selected. How can I make the values in this row appear as durations of minutes and seconds rather than 3-digit decimals? For example, rather than appearing as 9.84 I would like the value of Cell Y6 to appear as 9:50 or 9min 50sec. (obviously .84x60seconds 50 seconds). I tried changing the cell formats from "number" to "duration," but no change is made. Using the "duration" format does however work if I am manually entering the decimal value into the cell rather than allowing it to result from another caluclation within the spreadsheet. Is there a solution to this within Numbers '09? You can see why I would want the "pace" displayed in minutes and seconds. Thanks in advance!
    Ryan

    Hi Ryan,
    You wrote:
    "The problem is that my "Distance" is a row of automatically generated values resulting from ((Row1/60)*Row 6). Changing the format of Row 1 to minutes causes row two to be expressed as a duration, which obviously it shouldn't because it is a distance. The spreadsheet has to be designed so that all I have to manually input on each entry are Row 1 Values (Time) and Row 6 Values (Average Pace). The rest of the cells must be automatically poulated as a result of formulas."
    I'm assuming that where you say "Row 1" in this you mean "Row 2", which is labeled "Time" in the example in the OP.
    In the original post, you presented a formula from cell Y6. Replacing the Header labels in that formula's cell reference with the Addresses of the referenced cells, the formula was:
    Y6: =Y2/Y3
    In this post, you are saying that Y6 contains entered data: "...all I have to manually input on each entry are Row 1 Values (Time) and Row 6 Values (Average Pace).
    Which is correct?
    Regards,
    Barry

  • Default value for Read-Only Picklist Field

    Hi, all--
    I would like to have a default value ("Undetermined") for the "Associated Account" read-only picklist value. I have an account record of this value for this purpose. This is because if there is no value in the field, the record will not be included in a report that includes the field. I do not want to make the field required at this point.
    Field management doesn't appear to allow any default value for read-only picklists. Does anyone know how to get around this, either at the lead record stage or at the lead report stage (without resorting to an analytic, which won't work for what we are doing)?
    Thanks.

    That's a great question. It doesn't appear as though you can select it from the typical method of Admin | Application Customization | Lead | Lead Field Setup | Associated Account.
    Have you tried creating a workflow to populate the field using Before Modified Record Saved?

  • How to overwrite the value of a struts variable value using struts only

    Say i define a variable using struts in my jsp
    <bean:define id="aVar" value="abc" />
    Now the variable has a value of abc , how can i overwrite it again to have another value --say "123"..
    I need to change its value using struts only and not scriplet.
    Kindly help ....

    This page may be helpful:
    http://www.exampledepot.com/egs/javax.servlet.jsp/usebean.jsp.html

  • Result Processing - Additional results work only when any of the "Output Name" Enabled

    Only if i   ENABLE  any result type  only then the SequenceFilePostResultListEntry    is called
    the thing is I have aditional results & I save them in TDM format
    hence I dont need  the options from the   Result processing  
    is this  functional behaviour  expected from   teststand

    Hello aparab,
    i have greated a StationGlobals ReportActivated and fill this global in the callback
    ReportOptions with the the flag, if the report generation is disabled or not.
    In the SequenceFilePostResultListEntry a if structure is insert that ckecks the flag.
    Hope this helps.
    best regards
    Alexander Glasner
    AE NIE
    Attachments:
    SequenceFilePostResultListEntry.seq ‏11 KB

  • Report results displays only (*), no numeric values.

    Dear all,
    The report result only displays asterick (*), no numeric values. But the field in the result thus has numbers which can be seen in display at the top in the excel sheet. why?
    Do i need to make any changes in Query properties or something else??
    Please advise.

    Hi,
    You should be trying to work to different units of measure or different currency. If you do any calculation with two values which has different unit then the result will be so.
    use NODIM() of the keyfigure and do the calculation. create a formula and add NODIM to keyfigure, then you should be able to see values but you will not get the unit along with value.
    Else you should go for conversion of units to single one and then you can get both values and units.
    Hope this helps
    Regards
    Akhan

  • Display only the result rows only by using condition or any other way

    Hello Everybody,
    I've a web report where I want to diplay ony the result rows and don't want to display the detail rows at all. I could hide the detail rows but these rows still appear without any value in the key figure fields.
    I tried to revove the characteristic field from the drilldown but it doesn't show the report correctly. Then I tried to write a condition to filter the detail rows but this condition doesn't apply to the result rows so this effort also didn't work for me.
    Is there anyway we can display the report with only the result rows ? I've already tried to find out a solution on SDN but couldn't get the solution eventhough I found many posts on this kind of requirement.
    Any help would be greatly appreciated.
    Thanks
    Alok

    Please explain when you say
    "I tried to remove the characteristic field from the drill down but it doesn't show the report correctly"
    What is problem there? What result do you get. If possible please provide  details of columns layout and few numbers

  • How to set value from LOV only as a default reference not enforce validate check?

    In jdev 11.1.2.3,
    By creating  List of Value(LOV) for an attribute of a VO, I can get default value for the current VO's attribute from the lookup table, but it will also enforce a validate check for that value.
    If I input a value which is not in the lookup table, then errors will raised.
    Now I hope I can get default value from LOV, and can also input some new value (and this new value can be insert into the lookup table by a database trigger) for the attribute/field without failure to pass the check.
    Any one can help?
    Thanks!

    Hi, Arun
    Your suggestion let me get to know how to create a new record in the customeActions facet of inputComboBoxListOfValues, which I donot know before. It's great. and thank you very much.
    However, my current issue is a different requirement, let me describe it clearly as:
    I have a formlayout to input a field value which can be from a lookup table, or if this value is not in the lookup table then it can also be input without raising value validation check failure.and this new value can be added to the lookup table at the same time.
    for example, there is a FK attribute deptno in the EMP table, in a form for editing EMP attributes, user can input deptno value which is already in the DEPT lookup table by selecting from a LOV. also can input some new value which cannot be selected from the LOV, and this new deptno value will be posted to database both in EMP and DEPT table.
    The issue is, after create a LOV for deptno attribute in EMP VO, there will be a enforced value validation check, so new values cannot be input in EMP unless it is input into DEPT first.
    (http://docs.oracle.com/cd/E37975_01/web.111240/e16182/lists.htm#BABBJFBB)
    List of values are designed to return valid values only. As a result, validation rules defined on data source view object attributes will be suppressed.
    My question is: how to disable this enforced value validation for a LOV-enabled field?
    (There is other means to ensure user will input valid value for this field, for example ask him to double input.)
    Thanks again!
    bao

  • LOV Displays the Return Value when Read Only

    Greetings,
    I searched for a question/answer for this, but didn't find this exact scenario mentioned, but I may have missed it. If you know of this already been asked/answered just point me to the thread.
    On APEX version - 4.1.1.00.23
    I have a LOV that is populated by a dynamic action from another LOV. That works great. Depending on the value of another page item the 2nd LOV is Editable or Read Only. The problem is that when the 2nd LOV is Read Only the result value (an ID) displays instead of the display value.
    1 - Why is this?
    2 - How do I prevent this from happening?
    Also, I don't want 2 separate page items (one for edit, one for display) for the 2nd LOV, because the 2nd LOV also has a dynamic action on it to populate a 3rd LOV. The population of the 3rd LOV works great, whether the 2nd LOV is editable or read only.
    = = = = = = = 2nd LOV SQL = = = = = = =
    select sub_com_desc||' - '||commodity_desc d, defect_code_header_id r
    from qcis_defect_code_header
    where inactive_date IS NULL and plant_id = :P10_PLANT_ID
    order by sub_com_desc
    = = = = = = = = = = = = = = = = = = = =
    Thanks, Tony
    Edited by: cloaked on May 8, 2013 12:11 PM

    I've decided to try a different approach. Since the Select List LOV was Read Only and not populating correctly it was causing a session state error when inserting the row. So, I've made the Select List LOV editable, but it shouldn't be. I now need to disable the page item using JavaScript to prevent it from being changed. I need to do so only when a page item contains a certain value.
    Will someone share an example of JavaScript snippet of code I need to use? (I'm not much of a JavaScript coder.)
    The page item I need to disable is named - P10_DEFECT_HEADER_ID
    I need to disable it when P10_MAP_TYPE = 'P'
    Thanks, Tony
    Edited by: cloaked on May 15, 2013 1:00 PM

  • Get the sum of values and show only max(Date)

    Hi,
    I have a below query and the value
    select PO_No,DATE,RCVD,LINE_QTY,QTY_INVCD,PART_NO from Purchase                         
    PO_No     DATE     RCVD LINE_QTY QTY_INVCD     PART_NO
    PO1460 12/02/2007 11     20     12     0995-13
    PO1460 13/12/2006 4     20     12     0995-13
    PO1460 05/04/2007 5     20     12     0995-13
    In the above table,
    PO_No ,Line_Qty ,Qty_INVCD,Part_No all are same value.
    Now I want the sum ( rcvd,line_qty)
    i.e.,
    Select po_no,date,sum(rcvd) over (partition by line_quantity) RCVD,line_qty,qty_invcd,part_no from Purchase
    Its look like
    PO_No     DATE     RCVD LINE_QTY QTY_INVCD     PART_NO
    PO1460 12/02/2007 20     20     12     0995-13
    PO1460 13/12/2006 20     20     12     0995-13
    PO1460 05/04/2007 20     20     12     0995-13
    Now what I want is
    I want the value for only max(Date)
    b]PO_No     DATE     RCVD LINE_QTY QTY_INVCD     PART_NO
    PO1460 05/04/2007 20     20     12     0995-13
    How will I write a query?
    Likewise I have many PO_No PO100,PO101,PO102,..........

    No need to use subquery to get this result:
    WITH data AS (select 'PO1460' po_no, to_date('12/02/2007','dd/mm/yyyy') datum, 20 recvd, 20 line_qty, 12 qty_invcd, '0995-13' part_no FROM dual
    UNION all
    select 'PO1460', TO_DATE('13/12/2006','dd/mm/yyyy'), 20, 20, 12, '0995-13' FROM dual
    UNION all
    select 'PO1460', to_date('05/04/2007','dd/mm/yyyy'), 20, 20, 12, '0995-13' FROM dual
    UNION all
    select 'PO1462', TO_DATE('13/12/2006','dd/mm/yyyy'), 30, 20, 12, '0995-13' FROM dual
    UNION all
    select 'PO1462', to_date('15/04/2007','dd/mm/yyyy'), 15, 20, 12, '0995-13' FROM dual
    UNION all
    select 'PO1462', TO_DATE('13/12/2006','dd/mm/yyyy'), 40, 20, 12, '0995-13' FROM dual
    UNION all
    select 'PO1461', to_date('15/04/2007','dd/mm/yyyy'), 15, 20, 12, '0995-13' FROM dual
    UNION all
    select 'PO1463', TO_DATE('13/12/2006','dd/mm/yyyy'), 30, 20, 12, '0995-13' FROM dual
    UNION all
    select 'PO1463', to_date('15/04/2007','dd/mm/yyyy'), 15, 20, 12, '0995-13' FROM dual
    SELECT po_no, sum(recvd) keep (dense_rank first ORDER BY datum desc)
    FROM data
    GROUP BY po_no
    will do the same

  • In custom report, is it possible to get value of field only? No style info?

    I need to build the following string in the results of a custom report:
    http://my.domain.org/myapp?A1=<#ORACLE.FIELD#>
    but when I run my report as a portlet, I get this instead, which leads to a "Page not Found" -
    http://my.domain.org/myapp?A1=<FONT CLASS=PortletText1><STYLEINFO PortletText1>ORACLE FIELD VALUE</STYLEINFO>
    When running my custom report as a portlet, is there a way to get the value of the field only, without the style info?
    Thanks for an help offered....
    Message was edited by:
    I_LOVE_PORTAL
    Message was edited by:
    I_LOVE_PORTAL

    Hi
    Feild status at entry time looks for the following combination
    S- Supressed
    D- Display
    R- Required
    O- Optional
    System looks for this above combination at first in Posting Key and then in FSV of account which we enter. For this partical purpose the the feilds in posting key are kept optional.
    Check the feild status of posting key & account T-code FBKP.
    thanks
    Colin Thomas

  • Passing values/results between condition type by using the formula

    Hi,
    I'm having one condition type (A), that is determining a result percentage based on Condition Table A. Based on the percentege determined in Condition Table A, I would like to set a custom field value in the Kondition record structure (KOMP) so that value will be considered within condition type B and accessing condition table B.
    So far the only way to set values that I could find was within the Requirement formula associated with condition type B. Are there any other options? And how can I acces the percentage that Condition Type A determined? I looked into all kinds of global tables, but could not find anything.
    Thanks a lot for your help!
    Doreen

    Shivanand,
    There's no need to post that much code when you could create a very short test case that demonstrates only the problem you are having.
    You're using &NAME. notation on something that isn't a page or application item. You can't reference PL/SQL variables that way (or any other way) outside the PL/SQL scope. For your situation, you could create a page item named P55_DOCID and assign it a value in the PL/SQL process (:P55_DOCID := DOCID;), then reference &P55_DOCID. in HTML areas like the success message.
    Scott

  • Quiz Results - Attachment Only?

    I have upgraded to CP2 and was testing the e-mail reporting
    function and now see the results as an attachment; is this the only
    way now or is there a setting to allow results to be sent in the
    message body? I have a server-side script that parses the body to
    port the results to a SQL DB and this would require a re-write....
    Anyone? Thank you.

    For LWAddict
    You might try this debug test.
    Open the HTML page.
    Insert the Javascript code --- alert(gstrEmailBody); --- in
    the sendemail() function. Will look like this --
    function sendMail()
    alert(gstrEmailBody);
    document.emailForm.action = 'mailto:' + gstrEmailTo +
    '?subject=' + gstrEmailSubject
    document.emailForm.elements["Results"].value = "\r" +
    gstrEmailBody;
    document.emailForm.submit();
    Save the HTML page.
    Run the test.
    When you click the send e-mail button in the test, you should
    get a gray box with the following content---
    Core Data
    "Status","Location","Raw Score","Max Score","Min
    Score","Time"
    "failed","5","20","50","0","00:00:26"
    Interaction Data
    "Date","Time","Interaction ID","Objective ID","Interaction
    Type","Correct Response","Student
    Response","Result","Weight","Latency"
    "03/01/2007","08:30:34","Interaction10082","Quiz10030","choice","A","C","W","10","00:00:05 "
    "03/01/2007","08:30:38","Interaction10245","Quiz10030","true-false","true","false","W","10 ","00:00:04"
    "03/01/2007","08:30:42","Interaction10284","Quiz10030","fill-in","the
    word","kkk","W","10","00:00:02"
    "03/01/2007","08:30:46","Interaction10322","Quiz10030","long-fill-in","yes","yes","C","10" ,"00:00:03"
    "03/01/2007","08:30:52","Interaction10356","Quiz10030","matching","0.A,1.B","0.A,1.B","C", "10","00:00:05"
    The exact content will depend on the number and types of
    questions.
    If you see the box, click OK. If this box shows the correct
    data then you problem is the browser or server does not support the
    javascript code for sending e-mail.
    The javascript code is ---
    document.emailForm.action = 'mailto:' + gstrEmailTo +
    '?subject=' + gstrEmailSubject
    document.emailForm.elements["Results"].value = "\r" +
    gstrEmailBody;
    document.emailForm.submit();
    You should check with your IT staff to solve this problem.
    As stated before, if you publish as a stand alone, you will
    not get any details or attachments.
    Hope this helps.

Maybe you are looking for

  • Apple-ID disabled daily - clueless people cause it, but can Apple fix it?

    I have a particular problem with an Apple-ID belonging to a family member. Her Apple-ID is disabled almost daily, forcing her to unlock it using two-step verification (a trusted device and her Recovery Key). Sometimes - unclear why - unlocking isn't

  • Dreamweaver CS5 fails to open XP-Resolution Here!

    Hi, We had an issue with Dreamweaver CS5 opening under a standard user on XP Pro SP3. The resolution.... Open msconfig and disable everything to do with Adobe. Simple! Don't mess with config files, re-install; it doesn't work! Stopping Adobe things f

  • Sharing an external hard drive - iMac and iPad

    I currently have an external hard drive connected to an iMac. I also have an iPad. How can I share the hard drive between both and have access to it from the iPad. The hard drive is a Western Digital 2TB My book.

  • Manage Multiple Sites?

    I have two sites created in iWeb; one personal and one a sample for my work. My personal site gets published to .mac, but I just wanted my sample work site published to a file. I selected the work site and then Publish to Folder, but BOTH of my sites

  • Have a problem with JCWDE

    Hello, I am having some trouble when I try to run the JCWDE command. The actual command I issue is:- JCWDE JCWDE.app But I just get the following error:- Exception in thread "main" java.lang.NoClassDefFound: com/sun/javacard/jcwde/main I don't know w