+ Reply to Thread
Results 1 to 7 of 7

Copy the Row if the Criteria matches

  1. #1
    Registered User
    Join Date
    10-10-2013
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2010
    Posts
    48

    Copy the Row if the Criteria matches

    Hello,

    I was in a middle of a creating a macro and got stuck in the below scenario.

    There are two sheets namely "Data Sh" and "Summary Sh". In the Data sh we need to match the Criteria "NO" in the Col H and copy the same row data but only four col data (i.e. C4:F4) and paste it in the summary sh.

    I had used the Offset function but it was giving an error. I'm attaching the Example Scenario file for your reference.

    Regards,
    Rajkumar H
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Copy the Row if the Criteria matches

    Try
    Please Login or Register  to view this content.

  3. #3
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Copy the Row if the Criteria matches

    Very nice, Jindon! But a question, what's the "(2)"?:
    Please Login or Register  to view this content.
    It appears to be a parameter for the paste, but doesn't match any XlPasteType constant (which usually only apply to PasteSpecial anyway).
    Last edited by leelnich; 05-12-2017 at 10:47 AM.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Copy the Row if the Criteria matches

    It's a Cells(2,1) and second protocol is optional.

  5. #5
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Copy the Row if the Criteria matches

    Yeah, that makes sense-you needed to move down a row- but I've never seen the Cells Keyword skipped before.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Copy the Row if the Criteria matches

    You can find in my posts, like
    https://www.excelforum.com/excel-pro...ml#post3321278

    Cells(1,1) is the default, so
    r(,2) means r.Cells(1,2) = r.Offset(,1)

  7. #7
    Registered User
    Join Date
    10-10-2013
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Copy the Row if the Criteria matches

    Awesome Jindon! thanks for your help on this. I had used "For each loop" for this scenario but the code which you have used is amazing, very simple and haven't seen anyone written in such a different manner.
    Even I would like to write code in such a way, could you help me with the required study material.

    Thanks & Regards,
    Rajkumar

+ 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 to another sheet that matches criteria
    By shmemushi in forum Excel General
    Replies: 7
    Last Post: 11-30-2015, 04:17 PM
  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. [SOLVED] Only copy rows across IF matches criteria
    By Shansy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2013, 10:00 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. Replies: 4
    Last Post: 08-23-2012, 05:26 AM
  6. 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
  7. Match 1 criteria if matches then copy the entire row plus 1 row above and below
    By khalid79m in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-27-2007, 11: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