+ Reply to Thread
Results 1 to 9 of 9

Copy only rows with data

  1. #1
    Registered User
    Join Date
    01-28-2015
    Location
    Tampa, FL
    MS-Off Ver
    2010
    Posts
    110

    Copy only rows with data

    I have this macro below that is auto-filtering my data and copying only specific columns to a new sheet.

    The problem I am running into is that it is coping the entire column, including blank rows past the last row of data. How can I modify this to only copy the rows that have data?

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 09-25-2019 at 01:34 PM. Reason: Please use code tags!

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

    Re: Copy only rows with data

    Try this...
    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.

  3. #3
    Registered User
    Join Date
    01-28-2015
    Location
    Tampa, FL
    MS-Off Ver
    2010
    Posts
    110

    Re: Copy only rows with data

    Where do I place that in the code or do I replace something?

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

    Re: Copy only rows with data

    You replace the existing .Copy line.

  5. #5
    Registered User
    Join Date
    01-28-2015
    Location
    Tampa, FL
    MS-Off Ver
    2010
    Posts
    110

    Re: Copy only rows with data

    I just did that and ran the macro. I get a Run Time 424 error stating "Object Required".

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

    Re: Copy only rows with data

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-28-2015
    Location
    Tampa, FL
    MS-Off Ver
    2010
    Posts
    110

    Re: Copy only rows with data

    Wow! You are a wizard! It worked perfectly and ran 10 times faster than what I originally had! For this macro below, is there a way to speed it up?

    '
    ' Reorder Columns
    '

    '
    Sheets("Open Inventory").Select
    Range("A1").Select
    Columns("T:T").Select
    Selection.Cut
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight
    Columns("L:M").Select
    Selection.Cut
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
    Columns("N:N").Select
    Selection.Cut
    Columns("D:D").Select
    Selection.Insert Shift:=xlToRight
    Range("A1").Select

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

    Re: Copy only rows with data

    Selecting ranges is not necessary and is time expensive.

    Please Login or Register  to view this content.

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

    Re: Copy only rows with data

    Hi tkbuc,

    If you notice in post #1 I added code tags for you and AlphaFrog has also used code tags as we request in the forum rules.

    Administrative Note:

    We would love to continue to help with your query; however, you need to include code tags around your code.

    Please take a moment to add the tags in post #7. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly.

    Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    HTH
    Regards, Jeff

+ 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. Replies: 3
    Last Post: 05-24-2018, 04:48 AM
  2. 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
  3. Replies: 4
    Last Post: 01-23-2017, 08:10 AM
  4. [SOLVED] insert rows based on number in cell and copy the data down into the new rows
    By pziefle in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-05-2013, 11:19 AM
  5. [SOLVED] Insert Multiple Rows Based Off Number in Cell and Copy Data From Above New Rows
    By tstell1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 04:15 PM
  6. Replies: 1
    Last Post: 05-19-2011, 09:53 AM
  7. Replies: 2
    Last Post: 04-21-2011, 07:13 PM

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