+ Reply to Thread
Results 1 to 4 of 4

Copy/Paste via a Macro - How do I get it to paste into next empy cell?

  1. #1
    Registered User
    Join Date
    07-26-2021
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel for Mac (365 subscription) Version 16.51
    Posts
    24

    Copy/Paste via a Macro - How do I get it to paste into next empy cell?

    Hi guys,

    I have built a template sheet for recording the details of new purchase orders.
    I use it to calculate a few things.
    Once those calculations are done I want to copy some of the details, and paste them in the next empty rows on another sheet.

    I built a button, recorded a macro of me copy and pasting, and assigned it.
    It works fine EXCEPT it pastes the data into whichever cell is active on the "destination" sheet.

    I want it to paste into the next empty cell in column "B" on that sheet.

    I have a hunch I should be able to alter the code in the macro?
    My knowledge in this area is very rudimentary...

    I have attached the file and a screenshot of the current macro.

    Thanks in advance.

    Screen Shot 2021-08-12 at 10.00.43 pm.png
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,698

    Re: Copy/Paste via a Macro - How do I get it to paste into next empy cell?

    I didn't find a button anywhere.

    Because your code does not specify which worksheet it is copying from, it will use whatever sheet is active. I assume you intend for that to be Template, since you are pasting to Stock on Hand (your description here just refers to "destination"). In your case, it would be better to make this assumption explicit.

    Also, you do not have to Select something to copy it, despite the way the macro recorder gave it to you.

    If you want to paste to the next available row of Stock on Hand, you can find that row as shown here.

    Also, why are you copying from Range("A2:C10") of Template when there is data only in A2:C4?

    I have rewritten your code as follows:
    Please Login or Register  to view this content.
    It is hard to understand your overall problem. In you example you are copying data from a template that is already in the Stock on Hand sheet. We can probably give you better advice regarding the whole package if you explain the model of how you are going to use this file.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    07-26-2021
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel for Mac (365 subscription) Version 16.51
    Posts
    24

    Re: Copy/Paste via a Macro - How do I get it to paste into next empy cell?

    Hi Jeff,

    Thanks very much for your reply.
    Man, that code is pretty foreign to me, but I copied it over and it works nicely.

    The "Template" page is just that - a template which will be used to create new sheets.
    These sheets will have unique names.
    I imagine this part of the macro code - Worksheets("Template").Range("A2:C10").Copy .Cells(LastRow + 1, "B") - will stop working if the sheet has different name? Is there a way to rewrite the code so it uses a more general reference, like the sheet the button is located on? Instead of the name of the sheet?

    I suspect I'm going to need a short course on Visual Basic if I want to really start tinkering with macros.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,698

    Re: Copy/Paste via a Macro - How do I get it to paste into next empy cell?

    If you are using Template to create new sheets, and Template has data only in A2:C4, why do you need to copy A2:C10?

    To copy the data from Template to the sheet the button is located on:
    Please Login or Register  to view this content.
    Here is the code with explanation:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy text from a cell paste to website search box and copy & paste results in same sheet
    By JohnnyBoyxxx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2020, 06:06 PM
  2. Replies: 0
    Last Post: 01-13-2016, 08:50 PM
  3. Copy & paste in macro doesn't paste all cells
    By pltrapper in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-13-2013, 09:22 AM
  4. [SOLVED] Simple copy and paste macro- Paste special help needed.
    By hernancrespo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2012, 07:02 AM
  5. 2 Macro's: only vertical copy/paste action and copy-paste 14 columns to the right.
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2010, 10:34 AM
  6. Copy and Paste macro needs to paste to a changing cell reference
    By loulou in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2005, 07:06 AM

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