+ Reply to Thread
Results 1 to 6 of 6

copy range X number of rows until empty issue

  1. #1
    Registered User
    Join Date
    07-12-2013
    Location
    toronto, canada
    MS-Off Ver
    Excel 2007 & MAC excel 2011
    Posts
    46

    copy range X number of rows until empty issue

    Hello All, I have a vba that copies a range of rows from columns Q-AY, the rows can be 1 to whatever (rows are line items on an order, so 1 order can be only 1 item, another order can be 50...).

    The vba works but my issue is when it is copying the rows it is adding blank rows which is not making sense i.e. 2 line items but if I step through the macro 22line items are highlighted when I step into the range copy command but I do not see anything wrong with the logic.

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: copy range X number of rows until empty issue

    Range("Q2:AY2" & i + 1).Copy

    You are actually saying range("Q2:AY22")

    Possibly
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: copy range X number of rows until empty issue

    Another approach

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    07-12-2013
    Location
    toronto, canada
    MS-Off Ver
    Excel 2007 & MAC excel 2011
    Posts
    46

    Re: copy range X number of rows until empty issue

    Thank you for the reply davesexcel, I tried that line but received a type mismatched error.

  5. #5
    Registered User
    Join Date
    07-12-2013
    Location
    toronto, canada
    MS-Off Ver
    Excel 2007 & MAC excel 2011
    Posts
    46

    Re: copy range X number of rows until empty issue

    Quote Originally Posted by AlphaFrog View Post
    Another approach

    Please Login or Register  to view this content.

    AlphaFrog, wow, thank you, I never imagined 3 lines would accomplish the same thing so efficiently, works like a charm. Unfortunately, means I have a heck of a lot more learning to do.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: copy range X number of rows until empty issue

    You're welcome. Thanks for the feedback.

    In your original code, I think this would work...
    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. [SOLVED] How to combine range copy with textbox value into next empty rows
    By Dean Zuki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2018, 02:35 AM
  2. Issue trying to copy to empty row in workbook
    By chrisellis250 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2017, 10:03 AM
  3. Insert set number of rows between data and copy and paste data above empty rows
    By Orionm45 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2017, 11:35 AM
  4. [SOLVED] Copy & Paste Range to Next Empty Row "x" number of times
    By JBMaine in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-17-2015, 09:09 AM
  5. Replies: 0
    Last Post: 06-24-2015, 06:26 AM
  6. Replies: 1
    Last Post: 02-11-2015, 07:47 AM
  7. First empty row in given range (i.e. C3:G16) - Run Time Error Issue!
    By ncortez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2012, 09:33 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