+ Reply to Thread
Results 1 to 8 of 8

VBA code to copy and paste a varying number of Rows

  1. #1
    Registered User
    Join Date
    09-17-2014
    Location
    Cambridge, England
    MS-Off Ver
    2016
    Posts
    58

    VBA code to copy and paste a varying number of Rows

    Hello,

    This will be a simple issue for most of you. I have a sheet that contains data between columns A and P. I need to copy all values in these columns from A2 down (A1 being the headers that I do not want copying) and across from P2 down. Now when I have recorded the Macro I simply used Shift+Control and Down and Shift+Control and Right to highlight all cells with values and then to capture all data. However the macro has kept just those values and the next time I run it (possibly with twice as many Rows as before) it is cutting off at the previous point.

    Any help?

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA code to copy and paste a varying number of Rows

    sx, are there blank rows in the middle of the data, or is it just solid data from row 2 to the last row? Also, which column is guaranteed to have data if the row should be copied?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    09-17-2014
    Location
    Cambridge, England
    MS-Off Ver
    2016
    Posts
    58

    Re: VBA code to copy and paste a varying number of Rows

    It will be just solid data. There may be just one row of data or 35 rows. But it will be solid and no breaks in it.

  4. #4
    Registered User
    Join Date
    09-17-2014
    Location
    Cambridge, England
    MS-Off Ver
    2016
    Posts
    58

    Re: VBA code to copy and paste a varying number of Rows

    Oh and there will always be at least one row of data (otherwise I do not run the report). Therefore A2 - P2 will always have data, it is just then a question of how many more rows there will be from then on.

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA code to copy and paste a varying number of Rows

    Will you be pasting onto another sheet also row 2 and down?

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA code to copy and paste a varying number of Rows

    This code assumes you are pasting the data in rows 2 down.. we can adjust if needed

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-17-2014
    Location
    Cambridge, England
    MS-Off Ver
    2016
    Posts
    58

    Re: VBA code to copy and paste a varying number of Rows

    It would actually be copied to B4 on a sheet called 'Daily Summary' and something else that has just popped into my head is that I would need it to Insert the copied cells as there is a total summary of the data in Cell B5. Therefore I will be looking to have the copied data inserted and the cells moved down on the 'Daily Summary' Sheet.

    Should have really mentioned that before!!!

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA code to copy and paste a varying number of Rows

    Lol yeah probably. Try this version:
    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. VBA Copy a Varying Number of Whole Rows
    By nosheal in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-22-2014, 12:28 PM
  2. [SOLVED] Macro to copy three cells to varying number of rows
    By socalobie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-20-2014, 12:45 AM
  3. [SOLVED] Macro - Create / Copy / Paste Formula every 5 rows for varying range
    By Jill Pleau in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-29-2014, 12:31 PM
  4. Copy and paste list with varying length to specific columns/rows
    By bruizer31 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 08:32 PM
  5. [SOLVED] Match, Copy and Paste Column Headers - varying number of columns
    By itcher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-19-2013, 10:49 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