+ Reply to Thread
Results 1 to 4 of 4

A visual basic value copy BUG?? - accounting format has copy problem!!

  1. #1
    yunyanl@gmail.com
    Guest

    A visual basic value copy BUG?? - accounting format has copy problem!!

    I just got an unbelievable behavior from excel when i did the following
    value copying:
    -----------------------------
    Sub mycopy()
    Range("A2:B2").Value = Range("A1:B1").Value
    End Sub
    -----------------------------

    I formatted cell A1 as accounting format (or currency format $) and
    input $0.0123 in A1.
    format cell B1 as general format and input 0.0123 into B1.

    After running the macro, you'll see the target values of A2 becomes
    $0.0100, B2 is 0.0123. (i'm using excel 2003)

    THe accounting/currency format just use the rounding automatically!!!
    Is this a bug? or a feature?

    BTW, i tried after to use ".copy" and ".PasteSpecial xlPasteValues",
    that works regardless. But not knowing the limit of range copy made
    million dollar difference in my analysis! DARN it!


  2. #2
    witek
    Guest

    Re: A visual basic value copy BUG?? - accounting format has copyproblem!!

    yunyanl@gmail.com wrote:
    > I just got an unbelievable behavior from excel when i did the following
    > value copying:
    > -----------------------------
    > Sub mycopy()
    > Range("A2:B2").Value = Range("A1:B1").Value
    > End Sub
    > -----------------------------
    >
    > I formatted cell A1 as accounting format (or currency format $) and
    > input $0.0123 in A1.
    > format cell B1 as general format and input 0.0123 into B1.
    >
    > After running the macro, you'll see the target values of A2 becomes
    > $0.0100, B2 is 0.0123. (i'm using excel 2003)
    >
    > THe accounting/currency format just use the rounding automatically!!!
    > Is this a bug? or a feature?
    >
    > BTW, i tried after to use ".copy" and ".PasteSpecial xlPasteValues",
    > that works regardless. But not knowing the limit of range copy made
    > million dollar difference in my analysis! DARN it!
    >



    I have the same. Definitely it's a bug.

  3. #3
    Peter T
    Guest

    Re: A visual basic value copy BUG?? - accounting format has copy problem!!

    This relates to Excel's automatic conversion of dates & currencies, which
    gets it right for users 'most' of the time.

    dim cur as currency
    cur = 0.0123
    [c4]=cur ' 0.01
    [c5] = cdbl(cur) ' 0.0123

    back to your issue, you'll note when you did -
    Range("A2:B2").Value = Range("A1:B1").Value

    that A2 is automatically formatted as currency, because the data type
    (VarType) of that element in the array is currency.

    You could do -
    Range("A2:B2").Value = Range("A1:B1").Value2

    which will place the intrinsic values but won't change the existing format.

    Regards,
    Peter T

    <yunyanl@gmail.com> wrote in message
    news:1150751935.883946.144010@p79g2000cwp.googlegroups.com...
    > I just got an unbelievable behavior from excel when i did the following
    > value copying:
    > -----------------------------
    > Sub mycopy()
    > Range("A2:B2").Value = Range("A1:B1").Value
    > End Sub
    > -----------------------------
    >
    > I formatted cell A1 as accounting format (or currency format $) and
    > input $0.0123 in A1.
    > format cell B1 as general format and input 0.0123 into B1.
    >
    > After running the macro, you'll see the target values of A2 becomes
    > $0.0100, B2 is 0.0123. (i'm using excel 2003)
    >
    > THe accounting/currency format just use the rounding automatically!!!
    > Is this a bug? or a feature?
    >
    > BTW, i tried after to use ".copy" and ".PasteSpecial xlPasteValues",
    > that works regardless. But not knowing the limit of range copy made
    > million dollar difference in my analysis! DARN it!
    >




  4. #4
    yunyanl@gmail.com
    Guest

    Re: A visual basic value copy BUG?? - accounting format has copy problem!!

    Wow Peter~! Thanks a lot! That ".value2" works amazingly fine!!
    Thanks a million for the tip.

    Peter T wrote:
    > This relates to Excel's automatic conversion of dates & currencies, which
    > gets it right for users 'most' of the time.
    >
    > dim cur as currency
    > cur = 0.0123
    > [c4]=cur ' 0.01
    > [c5] = cdbl(cur) ' 0.0123
    >
    > back to your issue, you'll note when you did -
    > Range("A2:B2").Value = Range("A1:B1").Value
    >
    > that A2 is automatically formatted as currency, because the data type
    > (VarType) of that element in the array is currency.
    >
    > You could do -
    > Range("A2:B2").Value = Range("A1:B1").Value2
    >
    > which will place the intrinsic values but won't change the existing format.
    >
    > Regards,
    > Peter T
    >
    > <yunyanl@gmail.com> wrote in message
    > news:1150751935.883946.144010@p79g2000cwp.googlegroups.com...
    > > I just got an unbelievable behavior from excel when i did the following
    > > value copying:
    > > -----------------------------
    > > Sub mycopy()
    > > Range("A2:B2").Value = Range("A1:B1").Value
    > > End Sub
    > > -----------------------------
    > >
    > > I formatted cell A1 as accounting format (or currency format $) and
    > > input $0.0123 in A1.
    > > format cell B1 as general format and input 0.0123 into B1.
    > >
    > > After running the macro, you'll see the target values of A2 becomes
    > > $0.0100, B2 is 0.0123. (i'm using excel 2003)
    > >
    > > THe accounting/currency format just use the rounding automatically!!!
    > > Is this a bug? or a feature?
    > >
    > > BTW, i tried after to use ".copy" and ".PasteSpecial xlPasteValues",
    > > that works regardless. But not knowing the limit of range copy made
    > > million dollar difference in my analysis! DARN it!
    > >



+ 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