+ Reply to Thread
Results 1 to 12 of 12

VBA coding to copy certain lines from one worksheet to another

  1. #1
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    VBA coding to copy certain lines from one worksheet to another

    I'm very, very new at VBA. I have been going on-line to try and create a code that will copy lines from one worksheet to another. This also involves calculations with days and if a date cell is empty to use today's date. Here is my code. I am getting an error message right now about the Next without For compile error, which I have the Next and the For. Could someone help me and let me know if I'm on the right path?
    Please Login or Register  to view this content.
    Last edited by davesexcel; 10-06-2021 at 01:36 PM.

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: VBA coding to copy certain lines from one worksheet to another

    Hi & welcome to the forum,

    Your code is missing closing an IF statement. I am very sure we can suggest a better way of writing this code if you provide a sample excel file along with what is expected
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: VBA coding to copy certain lines from one worksheet to another

    I need to be able to copy rows from the main worksheet to another based on if it's a certain type of Bid/Eval Type and calculating if the days between Assigned to Buyer date and Issue Date is greater than 15. If Issue Date is blank, we need to use today's date for the calculation. I will be doing this same thing for Issue Date to Closing Date and Closing Date to Award Date, but they will both be on different worksheets. I have attached a spreadsheet. I have only attached the pertinent information and a sampling of what is really on this worksheet.
    Attached Files Attached Files

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: VBA coding to copy certain lines from one worksheet to another

    To avoid double work, can you please re-post the file with the exact same structure of your original file. It seems that you deleted some columns in your sample file which resulted in changing the order, e.g. in your code, you look into column 26 ("Z") but your sample file ends on column "M". You may delete all the data or put xx for example but retain the same structure so you don't end up having a code that will work in your sample file but not in your original one

  5. #5
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: VBA coding to copy certain lines from one worksheet to another

    Sorry about that. Here is the correct workbook.
    Attached Files Attached Files

  6. #6
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: VBA coding to copy certain lines from one worksheet to another

    Try below code ...
    Please Login or Register  to view this content.
    Last edited by nankw83; 10-06-2021 at 03:27 PM.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  7. #7
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: VBA coding to copy certain lines from one worksheet to another

    It's giving me an error message of AutoFilter method of Range class failed. When I debug it, it lands on the .AutoFilter Lc, 1. I wish I knew enough about this language to understand what you gave me.

  8. #8
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: VBA coding to copy certain lines from one worksheet to another

    I slightly modified your original code- you can test to see if it works.

    Please Login or Register  to view this content.
    Last edited by deadlyduck; 10-06-2021 at 05:04 PM.
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

  9. #9
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: VBA coding to copy certain lines from one worksheet to another

    It ran, but it still didn't copy over those rows where the Cell 16 is empty, and I should have had 4 rows copy over if my formula worked and my code, which it didn't.

  10. #10
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: VBA coding to copy certain lines from one worksheet to another

    Quote Originally Posted by vanfel View Post
    It's giving me an error message of AutoFilter method of Range class failed. When I debug it, it lands on the .AutoFilter Lc, 1.
    It failed the first time because you already have the data filter which I removed yesterday to understand the file. Try below code ...
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: VBA coding to copy certain lines from one worksheet to another

    The code worked, however, not all records were copied. The ones missing are those that have an Issue Date that is blank, which should be considered Today's date. There are 4 missing. Also, if I needed only those copied by the first column as Active, can that be added to the code? So IFB and Active (column A). I was hoping that filtered by Active, would only bring those Active over. Sorry, should have thought that one through.

  12. #12
    Registered User
    Join Date
    05-19-2014
    Posts
    11

    Re: VBA coding to copy certain lines from one worksheet to another

    This is only giving me the last line of the data. I'm missing something in the coding where it copies all what I need and pasting it to the other sheet. I have looked and googled, and I can't figure this out. Thanks.

    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] Compact multiple lines of VBA coding
    By razvansd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-13-2021, 02:06 PM
  2. Excel Macro to copy and insert lines to a different worksheet and match values
    By wendya in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-10-2015, 02:56 PM
  3. Copy a block of lines/rows and paste to another worksheet
    By Ted608 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-02-2015, 07:27 AM
  4. Copy conditional lines from multiple worksheets to another worksheet
    By ryanDC in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-18-2013, 09:52 AM
  5. Automatically copy lines from one worksheet to another
    By apeters in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-24-2008, 05:46 PM
  6. [SOLVED] lines not printing on second copy of my excel worksheet
    By bjdeweese in forum Excel General
    Replies: 0
    Last Post: 11-08-2005, 12:30 PM
  7. soft-coding lines in a macro
    By GJR3599 in forum Excel General
    Replies: 2
    Last Post: 03-30-2005, 06:06 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