+ Reply to Thread
Results 1 to 5 of 5

copy cell if row matches

  1. #1
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    copy cell if row matches

    Sheet 2 is a data sheet with 2000 rows. Sheet 3 is a sheet with 1000 rows. Starting with the first row in sheet 3, I want to compare it to the rows of data on sheet 2 to see if there is an exact match in the first 6 cells of that row. If so I want the macro to copy the value in column “I” sheet 2 for that matching row and paste it on sheet 3 in column “O” for the row in question. Then go to the next row in sheet 3 and repeat the process till all 1000 rows are done. (note that there are some blank rows in both sheets)

    Example:

    Sheet 3 first 6 cells in a row starting in “A1” look like this
    20131123 GG 5.5F D fMd8000 2F x x x...

    If there is an exact match on sheet 2, sheet 3 will have copied “I1” from sheet 2 and pasted it at “O1” on sheet 3 . The above now will look something like this on sheet 3:

    20131123 GG 5.5F D fMd8000 2F x x x... 76

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: copy cell if row matches

    Hi, light,

    is there an unique identifier for the data sets like the item in Column A? If not could we add a new column A to both sheets and concatenate the values for Columns 2 to 7 to show the search criteria? Will there always be just one match or might there be more than one match?

    With the newly created searchcriteria you could use a loop for sheet3 using only the cells with data by using SpecialCeclls(xlCellTypeConstants, 23) and using a For Each rngCell in range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTyoeConstants, 23), use WorksheetFunction:CountIf to check if this item is available on Sheet2, use Find for Column A on Sheet2 if the result is greater than 0, set a range to the first found, copy over by using the rows of the ranges as part of the cells. At the end of the macro delete the first column on both sheets. Not that complicated, is it?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: copy cell if row matches

    In looking for a macro to this problem, I have come across methods that say to use a unique identifier but this does not apply in this case.

    I do have a macro that checks the first 6 cells on a sheet for duplicates and if they are identical deletes the duplicate row(s). That macro is performed on sheet 2 to clean it up. I'm just not sure how to turn the macro into checking for identical rows between 2 sheets and not deleting but adding a copied value to the end of all rows on sheet 3. This is what I have that identifies duplicates between the first 8 cells (I can change it to 6 or whatever)on the same sheet then deletes them. I'm sure it can be modified to check for identical rows in the first 6 cells between sheets and do a copy/loop.

    Please Login or Register  to view this content.
    Last edited by light; 12-08-2013 at 08:13 PM.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: copy cell if row matches

    Hi, light,

    you should add code-tags to your procedure as requested by Forum Rule #3.

    Please try this code on a copy of your workbook:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: copy cell if row matches

    Thank You HaHoBe in Germany. Works great!

+ 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 cell information from one worksheet if a cell matches the criteria
    By grammydeb52 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-02-2013, 01:00 AM
  2. Copy whole row if criteria matches one cell
    By HayleyH86 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-21-2013, 07:33 PM
  3. Replies: 3
    Last Post: 12-17-2012, 11:16 PM
  4. [SOLVED] Copy Rows if first cell matches criteria
    By amq in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2012, 11:23 AM
  5. How to copy rows where a single cell matches certain criteria?
    By Sccye in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-16-2011, 09:42 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