+ Reply to Thread
Results 1 to 17 of 17

Copy Data to new Workbook based on if/then

  1. #1
    Registered User
    Join Date
    08-08-2016
    Location
    Jersey
    MS-Off Ver
    2013
    Posts
    9

    Copy Data to new Workbook based on if/then

    I need some help. I'm terrible at writing code, but I understand it enough to edit it to work for me.

    Anyway, I'm at a loss. I can figure out how to copy to a new sheet, but I need a new workbook. I want to copy a row to a new workbook based on an if/then statement. Basically, if column I is occupied and column J is blank, then copy the whole row to new workbook (call it, Open PO Report.xlsx). Any pointers?


    Thanks!

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-08-2016
    Location
    Jersey
    MS-Off Ver
    2013
    Posts
    9

    Re: Copy Data to new Workbook based on if/then

    That was fast!

    It works in theory. However, it only takes the last row of data, not every instance where the criteria isn't met.

    Also, running that code made me realize a few things that I would additionally need. The data pulled from the workbook should go to an existing file (so it's properly formatted). And, the workbook the data is being pulled from is coming from three sheets.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    It should pick up all the data where the criteria is met. At least it did when I tested it. We need to know the name of the existing file. Do you want the data from the three sheets consolidated into one in the existing file?

  5. #5
    Registered User
    Join Date
    08-08-2016
    Location
    Jersey
    MS-Off Ver
    2013
    Posts
    9

    Re: Copy Data to new Workbook based on if/then

    It's only grabbing the last row where the criteria is met. For example, the sheet I'm testing with has 4 rows filled out. 2 where the criteria is met (row 2 & 3). Only row 3 showing when the code is run.

    Yes, I would want the data from the 3 sheets consolidated into the existing file.
    Destination file = "Open PO Report.xlsx"

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    Can you attach a sample where it is not picking up?

    Your answer:

    Yes, I would want the data from the 3 sheets consolidated into the existing file.
    Destination file = "Open PO Report.xlsx"

    Do you want those 3 sheets consolidated into 1 sheet in the destination. or 3 separate sheets?

  7. #7
    Registered User
    Join Date
    08-08-2016
    Location
    Jersey
    MS-Off Ver
    2013
    Posts
    9

    Re: Copy Data to new Workbook based on if/then

    Both files are attached. Again, appreciate you taking the time to check this out for me!
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    Unfortunately, I have too run. If no one else helps. I'll see what I can do tomorrow.

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    Try:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-08-2016
    Location
    Jersey
    MS-Off Ver
    2013
    Posts
    9

    Re: Copy Data to new Workbook based on if/then

    Thanks for taking another shot! However, I got;

    Run-time error '9'
    Subscript out of range

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    Which line is highlighted?

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    Check the red too see if they exist.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    08-08-2016
    Location
    Jersey
    MS-Off Ver
    2013
    Posts
    9

    Re: Copy Data to new Workbook based on if/then

    Set ws2 = Workbooks("Open PO Report.xlsx").Sheets("Sheet1") <---is highlighted. Even put the full file path for the workbook and still had the same problem.

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    Is there a "Sheet1" ? Is the Capital "O" really a capital "O"? or a 0 (ie zero).

  15. #15
    Registered User
    Join Date
    08-08-2016
    Location
    Jersey
    MS-Off Ver
    2013
    Posts
    9

    Re: Copy Data to new Workbook based on if/then

    Yup, everything is there. Would it be easier to have the pulled info sent to another sheet instead?

  16. #16
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy Data to new Workbook based on if/then

    What about the file extension? is it .xlsx? or .xlsm or other?

  17. #17
    Registered User
    Join Date
    08-08-2016
    Location
    Jersey
    MS-Off Ver
    2013
    Posts
    9

    Re: Copy Data to new Workbook based on if/then

    the extension is .xlsx

+ 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 data into a new workbook based on inputs
    By rongil20 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2015, 04:52 AM
  2. Copy from another workbook based on data in a column
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 05-11-2015, 12:58 PM
  3. Copy Data from workbook into another based on certain criteria
    By Rossko7226637 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-07-2015, 08:48 AM
  4. Replies: 6
    Last Post: 01-29-2013, 07:01 AM
  5. Replies: 4
    Last Post: 09-15-2012, 02:18 PM
  6. copy data based on workbook name
    By ciprian in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2011, 03:34 AM
  7. Copy data from a range in a workbook based on a value in another
    By DJ Dusty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2006, 10:00 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