+ Reply to Thread
Results 1 to 5 of 5

How to copy rows from one sheet to another based on a condition in a third sheet

  1. #1
    Registered User
    Join Date
    02-05-2022
    Location
    Bulgaria
    MS-Off Ver
    Microsoft 365 apps for enterprise
    Posts
    43

    How to copy rows from one sheet to another based on a condition in a third sheet

    Dears,

    I want to copy every row in sheet1 that contains the code of product which is in sheet2 to copy them in sheet3

    I have this code but I cannot make it for multiple range for example to get the range of A:A in sheet2 or A1:A8000 and copy the rows that match in sheet3. It only works if I put the exact code of the product.

    Sub Copy_Criteria_Text()

    Application.ScreenUpdating = False
    With ActiveSheet
    .AutoFilterMode = False
    With Range("A1", Range("A" & Rows.Count).End(xlUp))
    .AutoFilter 1, "12X3456"
    On Error Resume Next
    .Offset(1).EntireRow.Copy Sheet3.Range("A" & Rows.Count).End(xlUp).Offset(1)
    End With
    .AutoFilterMode = False
    End With
    Application.ScreenUpdating = True
    Sheet3.Select

    End Sub


    I gave only 2 examples but the actual criteria should work for 100+ product codes so something like A1:A200 in sheet2 can work or A:A like I wrote above.

    Thank you in advance!
    Attached Files Attached Files

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

    Re: How to copy rows from one sheet to another based on a condition in a third sheet

    Give a header in Sheet1!A1 like ID or any.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-05-2022
    Location
    Bulgaria
    MS-Off Ver
    Microsoft 365 apps for enterprise
    Posts
    43

    Re: How to copy rows from one sheet to another based on a condition in a third sheet

    I tried the code but I probably should have given the whole table to the right as there are empty cells and probably this is what is confusing the code.

    I have attached the rest of the columns as an example in my worksheet. When I used the code, it got me only Row 1 from sheet1.

    Thank you!
    Attached Files Attached Files

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

    Re: How to copy rows from one sheet to another based on a condition in a third sheet

    Please Login or Register  to view this content.
    Last edited by jindon; 09-14-2022 at 03:30 AM. Reason: Fixed, for blank row/column within data range.

  5. #5
    Registered User
    Join Date
    02-05-2022
    Location
    Bulgaria
    MS-Off Ver
    Microsoft 365 apps for enterprise
    Posts
    43

    Re: How to copy rows from one sheet to another based on a condition in a third sheet

    Thank you very much that works perfectly!!!!!
    )))))

+ 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 from two sheet to one sheet based on six condition
    By MKLAQ in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-19-2021, 05:25 PM
  2. Copying rows from sheet 1 to sheet 3, based on if condition.
    By Mooohan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2015, 11:57 AM
  3. Deleting rows on one sheet based on a condition in another sheet in the same file
    By Steve2107 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-18-2014, 06:48 AM
  4. [SOLVED] Copy rows from active sheet to another sheet (last row) if condition in column X is met
    By mortless in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-17-2013, 08:11 AM
  5. [SOLVED] Copy from one sheet to other sheet based on condition
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-14-2013, 04:58 PM
  6. macro to copy rows to another sheet based on condition mentioned in another workbook
    By sona_tejas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2013, 06:23 AM
  7. Copy rows from a master sheet based on condition
    By Rohun Heesen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2011, 08:33 PM

Tags for this Thread

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