+ Reply to Thread
Results 1 to 6 of 6

Copy and paste data if condition is met

  1. #1
    Forum Contributor
    Join Date
    03-14-2015
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    279

    Copy and paste data if condition is met

    Hi I would like some help with a VBA code. I am struggling to collect all this information from a spreadsheet. Notes: the spreadsheet may have 10, 20, 100 records horizontally however all records are below the word REJECT. It also may have from 1 up to 10 records vertically. Basically I want to copy the four cells below the word REJECT (in yellow) plus the 3 adjacent cells (please see attached example) and paste them in the sheet "Data".
    The condition would be "if there is data below the word REJECT, select the data below, copy and paste them in the sheet Data". If possible put a message that says the number of records registered.

    Thanks you in advance, this will save me a lot of time.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Copy and paste data if condition is met

    Use this code, and run "FindValues" - note that your sheet Production had an extra space at the end, which you may want to fix, both on the sheet and in the code:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    03-14-2015
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    279

    Re: Copy and paste data if condition is met

    Thank you Bernie for the quick reply. I gave it a try and it worked, however when I added additional information the code did not consider it, please refer to the attach and see records in green. Those were not imported.
    What I noticed is that the code is only copying what is just below the word REJECT but there could be more rows with information from 1 up to 10 records / rows.

    Thanks again
    Attached Files Attached Files
    Last edited by fabian_76; 01-24-2022 at 07:02 PM.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Copy and paste data if condition is met

    I'm not sure what I did but I had a selection object in this line that should not have been there - the second line of "DoCell" should have been

    Please Login or Register  to view this content.
    As far as the 1 to 10 values, is there a consistent, logical way to determine the size of the data set that should be looked at?

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Copy and paste data if condition is met

    Hi fabian_76,

    Try this:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  6. #6
    Forum Contributor
    Join Date
    03-14-2015
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    279

    Re: Copy and paste data if condition is met

    Thank you Bernie you helped me a lot.

+ 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. Formula to copy and paste cell data when a condition is met.
    By ashishpatel34 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-30-2021, 06:48 PM
  2. [SOLVED] Copy paste of data if condition matches
    By dumdumbum in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-23-2020, 02:38 PM
  3. [SOLVED] copy paste the data if condition matches with dragging macro
    By dumdumbum in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-03-2020, 02:00 AM
  4. [SOLVED] Copy a range and paste data after certain row with condition
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2014, 09:24 AM
  5. [SOLVED] Copy Row data with condition and paste in new workbooks
    By tdugga in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2013, 03:41 PM
  6. Copy specific row data with condition and paste into new workbook
    By tdugga in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-23-2013, 06:32 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