+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    11-01-2009
    Location
    Bomlo, Norway
    MS-Off Ver
    Excel 97, Excel 2007
    Posts
    7

    Macro, Activate.Paste vs. Ctrl-v.

    This problem is somewhat related to my pervious post on this forum; With an europeean version of Excel, I have the following two numbers stored in my clipboard;

    21,6
    19,60454

    When I use the Ctrl-v the numbers paste nicely into my worksheet, but when I run the following simple macro;

    Sub Makro1()
    '
    ActiveSheet.Paste
    '
    End Sub

    The numbers comes out as;

    21,6
    1 960 454

    There is an information tag on cell 1, saying “this number is formatted as a text….”.

    Does anyone recognize this “problem” and knows how to fix it..?

    Thanks.

  2. #2
    Forum Guru Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    Cheshire, UK
    MS-Off Ver
    MS 97, 2003, 2007, 2010
    Posts
    2,900

    Re: Macro, Activate.Paste vs. Ctrl-v.

    Quote Originally Posted by Jiser001 View Post
    ......
    The numbers comes out as;

    21,6
    1 960 454

    There is an information tag on cell 1, saying “this number is formatted as a text….”.

    Does anyone recognize this “problem” and knows how to fix it..?

    Thanks.
    Format the cells as number, type in your 2 numbers, copy to clipboard, future pastes should be fine however , your number format 19,60454 isn't valid, it should be 1,960,454 that is probably why excel thinks its text rather than a number!

  3. #3
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: Macro, Activate.Paste vs. Ctrl-v.

    @simon
    your number format 19,60454 isn't valid, it should be 1,960,454 that is probably why excel thinks its text rather than a number!
    I disagree. The OP mentions European Excel, where the decimal point is actually a decimal comma, so

    19,60454 in European is 19.60454 in US/UK settings, which is a perfectly valid number format.

    Jiser, check your Windows regional settings, and also your Excel settings for delimiters!

    cheers
    Last edited by teylyn; 11-14-2009 at 07:51 AM.
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  4. #4
    Registered User
    Join Date
    11-01-2009
    Location
    Bomlo, Norway
    MS-Off Ver
    Excel 97, Excel 2007
    Posts
    7

    Re: Macro, Activate.Paste vs. Ctrl-v.

    Thanks to both of you.

    Unfortunately I was not precise when describing the environment I am working in. But Teylyn is right, the two numbers, - which are part of a huge series of numbers copied from a third part application, are valid numbers in my regional version of Excel. So the expected values are numbers; 21.6 and 19.60454 respectively. In my europeean Excel version denoted with a “,” as decimal separator instead of the “.”.

    When I paste these two numbers into my worksheet using “Ctrl-v”, it works perfect and my VB code can work further with them as numbers. However, if I use the VB code “ActiveSheet.Paste” to paste the content into my worksheet, it does not perform an instruction identical to “Ctrl-v”, and Excel treat the first number as text and multiply the last number with 10,000. Altering the regional settings in the controlpanel or altering the delimiters in Excel only alter the appearance of the outcome. Still the format is wrong. Any idea..?

  5. #5
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,661

    Smile Re: Macro, Activate.Paste vs. Ctrl-v.

    Good afternoon Jiser001

    I can't be sure how it works for numbers, and I'm trying to reach down in the dark recesses of the old grey matter here, but ...

    I seem to remember having a similar problem with dates and after much messing around came to the conclusion that while your worksheets are happy to work in the locally accepted format, VBA likes to work in the US format. So where us Europeans like to see dd/mm, the US format is mm/dd. This could be the situation with your numbers, ie UK / US format is 1,234.56 and the European format is 1.234,56.

    This doesn't really help you as I can't provide a sure workaround - rather than using paste, could you not read the value of the cells and copy them elsewhere, or copy using Format rather than paste. This is all just theoretical as I don't have access the European Excel ...

    HTH

    DominicB
    Now available : Ultimate Add-In 2007
    Integrates directly into the Office Excel Ribbon


    Download Ultimate Add-In v1.52 from www.dom-and-lis.co.uk
    90+ Utilities, 200+ Sub utilities last updated 25th April 2008
    Free!!

  6. #6
    Registered User
    Join Date
    11-01-2009
    Location
    Bomlo, Norway
    MS-Off Ver
    Excel 97, Excel 2007
    Posts
    7

    Re: Macro, Activate.Paste vs. Ctrl-v.

    Dear DominicB

    Yes I think you are on to something.

    It seems to me as when the VB(with English text menus) has control and running the “ActiveSheet.Paste”, the Excel environment are already altered, and the content in clipboard is interpreted different than in the Excel environment when I past with “Ctrl-v”. Does this make sense..?

    As for you pervious “problem”, I think that Teylyn remedy may work, - changing the regional setting in the control panel to US. But to my problem, that had no effect as the first number is regarded as text using the “ActiveSheet.Paste”, and to the second number change of regional settings only add thousand separator to the last number, but still interpret it wrong…

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0