+ Reply to Thread
Results 1 to 19 of 19

Copy and Paste by VBA

  1. #1
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Copy and Paste by VBA

    Hi, I need of a Macro to copy and past some cells on excel, i mean:
    I have 2 sheets: in the first one i have some data/numbers that I updat every week, so I have for every week different numbers. I have to copy these numbers on the second sheet, but i don't want to paste the numbers on the cells of the previous week. I tried to record a macro using excel and i got:
    Please Login or Register  to view this content.
    The problem is that using this macro I override the cells everyweek: i need that every week the new numbers have to be paste on the next column in the second sheet.

    Example
    Sheet 1
    Column 1 (09/19/11)
    1.2
    2.9
    3.4
    4.5
    5.6

    Sheet 2
    Column 1 (09/05/11) Column 2 (09/12/11) Column 3 (09/19/11)
    2.5 ||| 2.4
    2.6 ||| 3.5
    7.4 ||| 2.8
    8.9 ||| 5.2
    5.6 ||| 9

    As you can see I want to copy and past the value for the updated numbers. If I use the macro i've created i will every week write on the same interval.
    The macro should recognizes the blank cells (without any number) which follows written cells with number (in the example i want to paste the value on the column 3, and the following week on the column 4. etc...).

    Then I want also to copy from the second sheet the last 4 columns written with numbers on the first sheet: it's a dynamic copy and past because i want that the range of the copy and past would follow the updated cells.

    Thanks in advance.

    Damiele
    Attached Files Attached Files
    Last edited by dumbago; 09-19-2011 at 09:01 AM. Reason: Tags Code

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Copy and Paste by VBA

    Welcome to the forum dumbago.

    Please take a few moments to read the forum rules. Then add Code tags to your code sample.


    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    thanks, i hope that now it will be correct.

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy and Paste by VBA

    hi, dumbago, please check attachment, run code "test"
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    Quote Originally Posted by watersev View Post
    hi, dumbago, please check attachment, run code "test"
    I'm trying to use it in my file, i will inform you. Thank you very much!

  6. #6
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    Hi, it works, but may you do it on this file, because i'm not able to do it on mine. Thanks a lot!
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy and Paste by VBA

    please check attachment, run code "test"
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    Quote Originally Posted by watersev View Post
    please check attachment, run code "test"
    thanks, i will check it tomorrow...I really don't know how can I say to you thanks..

  9. #9
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    Quote Originally Posted by watersev View Post
    please check attachment, run code "test"
    Hi it doesn't work, because the macro copies only the last column but it is not added to the sheet 2.

    The macro you gave me yesterday works alone, but i wasn't able to use that macro in my file.

    If you have time, please help me.

    Last edited by dumbago; 09-20-2011 at 03:34 AM.

  10. #10
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy and Paste by VBA

    can you show the result you are expecting to obtain after using the code basing on your posted file?

  11. #11
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    ok, i will post the fiule in more or less 1 hour. thanks again!

  12. #12
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    This is the file: as you can see i wanna thgat every week the sheet2 (historical trend) grows for one column (the yellow one) that is taken from the sheet 1 (Summary&Data). I also want that in sheet 1 (Summary&Data) there should be a summary of the last 4 weeks of data (the grey colored) plus the actual week, the yellow one that is linked to other cells in the sheet. The steps are: I have every week different numbers linked to other cells in sheet1, in the yellow column. I have to copy this column in sheet2 (historical trend) in order to create a historical database: so i need o update every week the sheet2 with the number in the yellow column in sheet1. Then i have to copy and paste the last 4 columns (grey), except for the last i have copied before (the yellow), in the table in the sheet1. That is. May you help me? The firs macro you gave me worked so well, but the problem was that i wasn't able to use it in my file (that i cannnot give to you because is an important work's file) that i have replicated only for the part i need to upload.

    One thing more: i wuold like to update also a graph for the Histocal Trend sheet which change automatically the range (every week the number of the cell in the graph grows). But this is the last and less important problem. The more important is the previous.

    thanks again
    Attached Files Attached Files
    Last edited by dumbago; 09-20-2011 at 10:20 AM.

  13. #13
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy and Paste by VBA

    please check attachment, run code "test".
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    HI, i'm sorry, but it doesn't work

  15. #15
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy and Paste by VBA

    hi, dumbago, how do you check if it's working?

  16. #16
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copy and Paste by VBA

    Quote Originally Posted by watersev View Post
    hi, dumbago, how do you check if it's working?
    Hi, i have opened the file you sent to me and i've created a button and i'v assigned the macro test, but it doesn't work!
    I have also copy the text of the macro, and I pasted it in a new macro for my file, but it doesn't work.
    I you see the example i gave you, the last one, you have 8 sheets...every sheet is a step..you start with the first one in which i have nothing in the column TODAY (Sheet 0a) and nothing in the last column of the sheet 0b. Then i upload the file and in the sheet 1a there is the column date that is fulled by numbers and in the sheet 1b you have the last column filled (the yellow one). then the last fuor columns of the sheet 1b (excluyded the last one i've just filled in) has to be copied in the little table in the sheet 1a. then do it for every time i upload the file. but i want to have it in 2 sheets, not in sheets like in the file I sent you!

    However I have another idea. Let's invert the process:
    FIRST copy the last four columns oh the sheet Historical Trend (the 4 columns before the blank one)
    SECOND paste the columns copied before in the sheet Summary&Data in the little table, (the 4 columns that are already filled by numbers) excluded the column TODAY
    THIRD copy the column TODAY of the sheet Summary&Data
    FOURTH paste the column copied before (sheet Summary&Data) in the first blank column of the sheet Historical Trend.


    I hope i was able to tell you what i really need.

    Many thanks

  17. #17
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy and Paste by VBA

    ok, can you activate sheet "3a" and run the code. The result is on sheet "3a" and "3b". It was meant to work on the activesheet and sheet next to it.
    Last edited by watersev; 09-21-2011 at 11:20 AM.

  18. #18
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Copy and Paste by VBA

    please check attachment, run code "test"

    Please note date in B23 has been changed to a static date without formula for testing purpose.
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    09-19-2011
    Location
    Milan
    MS-Off Ver
    Excel 2003
    Posts
    11

    Smile Re: Copy and Paste by VBA

    Quote Originally Posted by watersev View Post
    please check attachment, run code "test"

    Please note date in B23 has been changed to a static date without formula for testing purpose.
    HI watersev..it works: I've changed some cells in the Macro due to my needs, and now it works.
    Thank you so much, I really appreciate your help.

+ Reply to Thread

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.6.0 RC 1