+ Reply to Thread
Results 1 to 19 of 19

Copy and paste a range of cells to the last blank row on a sheet - and clear contents

  1. #1
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    I am trying to write a macro to do the following:

    Copy range A1:K12 and paste the entire range to the last blank row within the sheet. Also, clear contents of the following cells within this range (B3,B4,C4,D4,E4,F4,G4,H4,I4,J4,K4,B5,C5,D5,E5,F5,G5,H5,I5,J5,B6,C6,D6,E6,F6,G6,H6,I6,J6,K6,B8,D8,F8,H8,J8,B9,B10,B11,B12)

    Any help greatly appreciated!

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    Did you turn on the macro recorder and record those steps?

    Do this will get you the meat of the macro and then if you post the macro here we can help you clean it up...

    or

    ...use this to help clean up your recorded macro Beyond Excel’s Macro Recorder
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    the code is as stated below although in this case A22 was the last blank cell in column A...i want it to be automated to find the last blank cell in column A on this sheet and paste the range accordingly. Also, not sure if 'Application.CutCopyMode = False' is necessary?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    sorry i meant NEXT empty cell not last empty

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    Not so sure this macro makes sense to me as it clear contents which were just pasted.

    Try...

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    should have been more clear..this range is a form that a user would fill out so when copied, i want the contents of the user defined fields(all but cells in column A within range) to cleared so the form is ready to be filled out again. The macro you provided works great and thank you. Just one question, since this is going to be run multiple times is there a way to make the 'Range("B24:K33").ClearContents' dynamic as it got an error on this line the second time running the macro(due to the copied range being below that range every time running the macro after the first time.)

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    Quote Originally Posted by glock9mm View Post
    Just one question, since this is going to be run multiple times is there a way to make the 'Range("B24:K33").ClearContents' dynamic as it got an error on this line the second time running the macro(due to the copied range being below that range every time running the macro after the first time.)
    Yes you can make it dynamic, but dynamic off of what?

  8. #8
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    off of where it is pasted. The second time i run this macro the range needed to be cleared would not be B24:K33 because it would be pasted to the next empty cell. So the second time it is ran it would need to clear contents of L24:U33 and so on everytime it is ran.

  9. #9
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    I would use some empty cells to hold the column number so the next time the macro is run the macro knows what columns were previously cleared...

    I used J1 and K1 to hold the column number and the next time the macro is run it adds 10 to the previous column numbers...

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    It appears that code works but i think i told you this would be pasted horizontally as opposed to vertically. Let me try to explain...

    The range I am using(and works with the first part of your code you sent) is A41:K55

    Please Login or Register  to view this content.
    When i run the above macro it copies the range (A41:K55) to A56:K70 because A56 is the next empty cell and I would need B58:K70 to be cleared. It would follow this same pattern every time the macro is run.

    Is this enough info to tweak the marco to clear contents dynamically?

  11. #11
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    Do you have a sample file you can attach?

    If I follow what you just said above...

    Copy A41:K55
    Paste to A56:K70 (next open cell in column A)

    Now you want to...
    Clear contents of B58:K70

    This overlaps what you just copied and pasted...

    I'm not following...Remember, I don't see the same file you are looking at...

  12. #12
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    example file.xlsm

    See attached example file

  13. #13
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    I am completely lost as to what you want...

    You talk about copying an area, clearing an area, and moving data to the right...

    In your sample file there is no example of before and after.. Please update with a before and after so I can see exactly what you want the macro to do.

  14. #14
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    example file.xlsm

    see attached w/ before and after. I just need the form copied to the next empty cell and all the user defined fields cleared out every time it is copied so the form can be completed by another user.

  15. #15
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    Okay I think this will do it which follows the pattern...

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    02-02-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    perfect! thanks so much for your help and patience

  17. #17
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    You are very welcome, but I must thank you for your patience with me.

    Thanks for the feedback

  18. #18
    Registered User
    Join Date
    12-05-2012
    Location
    Norway
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    Hi
    I have been following this thread with great interest and I'm trying to learn something as well.
    JeffreyBrown! If I use your solution in post #15 02-03-2013 at 12:38 but want the copied cells to be pasted in another sheet (sheet3), but otherwise exactly the same parameter. How can that be done?
    Regards from Panton
    Last edited by panton; 02-10-2013 at 05:09 PM. Reason: typo

  19. #19
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Copy and paste a range of cells to the last blank row on a sheet - and clear contents

    Hi Panton & Welcome to the Forum,

    Well it seems there may be a little bit more involved here, but in a nut shell, you simple qualify the sheet you need to paste too.

    Not only do you need to qualify the sheet, now you will possibly have to find the last row twice.

    Once on the source sheet and then on the destination sheet.

    I would love to help, but to make sure we get your requirements right, can you create a new thread plus upload a sample workbook with a clear before and after.

    You can PM me the new link and I will help you along.

+ 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