+ Reply to Thread
Results 1 to 7 of 7

Copy Paste values between sheets - values incorrect

  1. #1
    Registered User
    Join Date
    10-12-2010
    Location
    EUSA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Copy Paste values between sheets - values incorrect

    Please Login or Register  to view this content.

    All sheets located in the same workbook.
    I am copying a model number (Sheet "Models") into a bill of material spreadsheet (Sheet "Bill"), refreshing and taking the cost of the model (H2 cell) and copying it to another spreadsheet (Sheet "Cost Pricer") to develop a price list.

    The above formula plugs product model costs into two cells... C6 and C7.

    When I run the macro with only one cell (i.e. half the macro or eliminating the macro to plug a value into C7) everything works out fine. If I run the macro for additional cells (i.e. C7 or C8 or C9 or C10 etc)...the last cell will copy the correct values...but previous cells the values are incorrect and I am uncertain as to why this is happening...example:

    SHOULD BE:
    C6 $57.77
    C7 $58.99

    With one cell macro only I get
    C6 $57.77 (CORRECT VALUE)

    With more than one cell I get
    C6 $52.88 (WRONG VALUE)
    C7 $58.99 (CORRECT VALUE)

    Why does the addition of another cell to the macro cause inaccurate values in all cells except the very last cell in the macro?

    Thank you in advance
    Last edited by Leith Ross; 10-12-2010 at 12:45 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Copy Paste values between sheets - values incorrect

    Hello db41987,

    Welcome to the Forum!

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code using the # icon
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    To manually wrap your code, use these Bulletin Board Code Tags
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] at the end of the last line.

    To learn more about BB codes used in this forum, just click on the link below...

    Bulletin Board Codes Tags
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Copy Paste values between sheets - values incorrect

    Selecting is unnecessary, slows your code, and makes it hard to follow. The first half can be simplified to something like this:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    10-12-2010
    Location
    EUSA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Paste values between sheets - values incorrect

    Please Login or Register  to view this content.
    Thank you for the code optimization snippet...I've incorporated this.

    Unfortunately, my end result is the same. The values posted are only accurate for the LAST cell in the sub...the previous cells have incorrect values and I'm not sure why.
    Last edited by db41987; 10-12-2010 at 03:19 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Copy Paste values between sheets - values incorrect

    Have you stepped though the code and watched the values as they are copied and the cells as they calculate?

  6. #6
    Registered User
    Join Date
    10-12-2010
    Location
    EUSA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Paste values between sheets - values incorrect

    Quote Originally Posted by shg View Post
    Have you stepped though the code and watched the values as they are copied and the cells as they calculate?
    That's a good question.

    When I manually enter the model number into the Bill of Material spreadsheet it computes the cost correctly.

    When I run the script and watch the Bill of Material compute the cost...the costs shown are not correct for all of the models except the very last one...that one is correct.

    If I manually enter a model number, calculate and THEN run the script...that particular cell is computed properly...all others are in error except for the last one.

    Then...if I run the script immediately afterwards...it overwrites the correct cost with an incorrect cost...again...all cells wrong except for the very last one.

  7. #7
    Registered User
    Join Date
    10-12-2010
    Location
    EUSA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Paste values between sheets - values incorrect

    Okay I just found that on cells where a value of $0 is posted...instead of posting $0 it is posting the value in the cell underneath it...

    H2 is the proper cell...if it is $0 it is taking the value of H3 and posting it

    Not sure why?

+ 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