+ Reply to Thread
Results 1 to 26 of 26

Macro to copy/paste info in different sheets and to delete last entry

  1. #1
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Macro to copy/paste info in different sheets and to delete last entry

    Hello, I need a macro that will do the following:

    Copy from Sheet "DataEntry" C22 and paste it in Sheet "Calculations1" (E29)
    Copy from Sheet "DataEntry" E22 and paste it in Sheet "Calculations1" (G29)
    Copy from Sheet "DataEntry" C25 and paste it in Sheet "Calculations1" (E33)
    Copy from Sheet "DataEntry" E25 and paste it in Sheet "Calculations1" (G33)
    Copy from Sheet "DataEntry" G24 and paste it in Sheet "Calculations1" (E31)

    Every time the macro is executed I will do the same operation but to the next sheet called: "Calculations2", then "Calculations3"...and like that until "Calculations50" once it reaches Calculations50, if the macro is executed again it will display a window message like: "You can't enter more data"

    Also I will need a macro to delete the last entry of the previous macro, so that every time you execute it it will delete the last entry...and you can do it as many times as you want until you've deleted all of them.

    Thank you!
    Last edited by barcas84; 02-01-2012 at 09:50 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    These macros should work together to accomplish that.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-31-2012 at 07:55 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Hi! I'm a little confused... What do you mean by work together...? You mean put them in the same module? How do I execute them? Like if I wanna execute Deletesequential, do I have to execute also any of the others? Also to execute Copysequential do I have to execute SetCount...? Can you help me?

    Thank you!!!

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    The macros go into a standard code module. Then from your worksheet, pressing Alt-F8 presents your list of macros, you can run the CopySequential macro to copy to the next sheet (1-50), or run the DeleteSequential to delete the info from the last sheet with data. Both of those macros make use of the SetCount macro when needed. (read the macros you'll see)

    You should probably make the SetCount macro private so it does not display in the macro list when displayed.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Hi! Got it! I tried but is giving an error in the CopySequential in this line:

    Please Login or Register  to view this content.
    Says its out of range... Any ideas why?

    Thanks!!!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Sure, "out of range" means the current sheetname can't be found. Calculations20, for instance. The logic of the code seems correct to me, I'd have to have your workbook to test it. Click GO ADVANCED and use the paperclip icon to post up a copy of your workbook if you want me to.

  7. #7
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Sure, here it goes!!!!!! Thank you!
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Any news on this???

    Thanks!!

  9. #9
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Any news on this???

    Thanks!!

  10. #10
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Bump no response

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Looks like a typo in the first macro... fix this line:

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    HI, thanks for the reply!!! I was having another error, and it was because the DataEntry tab was actually called Data Entry (with a space) so I fixed it, and also the line you told me. Now, when I click the button, it doesn't come up with an error but it opens the Visual Basic and highlights the line of code in the macro:

    Please Login or Register  to view this content.
    Then I run it there manually without changing anything and it works... Why wouldn't it work in the first place with the button...?

    Also there is something that I didn't mention but that the macro needs to do.... The problem is that if I use it, let's say 10 times, it works until Calculations10, then if I reset everything and I want to start from the beginning, the macro keeps going when I left it, in Calculations10...and it won't go to Calculations1 until I run DeleteSequential 10 times.... So my question is, can you make a change so the macro will look the first available Calculationstab? Then if it has info it will jump to the next one... This way, when I reset everything, the macro will always start from Calculations1...

    Thank you!

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    The macro currently works in reverse, from last to most recent looking for the next empty sheet. You're saying you want to chaotically clear sheets from anywhere in the list and reuse them? Ouch.

    Also, yes, running the DeleteSequential multiple times would do what it was designed to do, free up one sheet at a time.

    An all purpose "reset everything" macro might look like this:

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Thanks for the Reset Macro! I'm currently using this one:


    Please Login or Register  to view this content.

    About the change in the process...yeah I'm sorry I forgot to mention it earlier... But basically the macro would have to go to Calculations1 in first place, and then jump to the next if Calculations1 has data already...and like that until it finds one empty, then it would paste the data there... The DeleteSequence should be the same.... I have one macro that does something like that but jumping 2 rows within the same sheet instead of jumping sheets...maybe it helps!


    Please Login or Register  to view this content.

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    The maybe just reverse the order the SetCount macro checks sheets:

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    PERFECT!!!!! Now it works beautifully!!! Thanks a lot for your help!

  17. #17
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Wait, are you sure? Looking at that again I think it would keep updating Calc2.... is that what it's doing for you and you didn't notice?

  18. #18
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    I think the SETCOUNT thing doesn't work any more, when you DELETE you always want to go from last sheet to first, but when you COPY new data you are now searching from first sheet to last looking for an empty one. So, I think the macros all need to change. Use these instead:

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    You are right!!! It wasn't working correctly... Now it is! But I have one more question... This workbook, when you enter the info it does the macro that you've written and also this one here:


    Please Login or Register  to view this content.

    Which copies the info in a list... Now my question is, how do I also delete the last record entered in this macro? Something like the DeleteSequential that you wrote but for this macro...

    Thanks!!!!

  20. #20
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    These two macros would replace your one CodeList macro:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 02-02-2012 at 02:17 PM. Reason: Corrected NR calc.

  21. #21
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    AddCodes gives an error, it says: " No cells were found"

  22. #22
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Also, how could I just clear the cells from Sheet ("PDF"), cells from B26 to B75?

  23. #23
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    1) I edited the AddCodes macro above, try that.

    2)
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Hi!, The Addcodes macro was having an error because there are to End If, but only one If so i deleted the second one leaving it like this:

    Please Login or Register  to view this content.
    And it doesn't give an error but it doesn't work either... I also tried deleting the other one, and same thing...

  25. #25
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy/paste info in different sheets and to delete last entry

    The code above is corrected. Try it again.

  26. #26
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Macro to copy/paste info in different sheets and to delete last entry

    Now everything works great! Thank you!!!!

+ 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