VBA - Copy/Paste row if cell contains specific value

DarkSmile

Board Regular
Joined
Feb 22, 2021
Messages
90
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to copy rows based on if a the cell has a specific value.
The code I tried :

VBA Code:
Sub Copy()

Dim StatusCol As Range
Dim Status As Range
Dim PasteCell As Range

Set StatusCol = ThisWorkbook.Worksheets("Import").Range("G2:G5000")

For Each Status In StatusCol

    If ThisWorkbook.Worksheets("NEW").Range("A2") = "" Then
        Set PasteCell = ThisWorkbook.Worksheets("NEW").Range("A2")
    Else

        Set PasteCell = ThisWorkbook.Worksheets("NEW").Range("A1").End(xlDown).Offset(1, 0)
    End If
    
    If Status = "New" Then Status.EntireRow.Copy PasteCell

Next Status
        
End Sub

Agenda IFS.xlsm
ABCDEFG
1NamedatetypeUnannouncedstandardexternal_certNrStatus
2test107/10/2022repeatUnannouncedIFS LCOID: 79631New
3test201/12/2022repeatUnannouncedIFS v7New
4test305/10/2022repeatUnannouncedIFS v7COID: 60342New
5test417/10/2022repeatAnnouncedIFS v7coid 36932New
6test505/12/2022repeatAnnouncedIFS LCOID: 60157New
7test628/10/2022repeatUnannouncedIFS v7COID: 11763New
8test728/11/2022repeatAnnouncedIFS v781040New
9test816/12/2022repeatAnnouncedIFS v7New
Import
Cell Formulas
RangeFormula
G2:G9G2=IFERROR(VLOOKUP([@Test],Archive!K:L,2,FALSE),"New")


The Status however is a formula that return Found or New, so may this be the issue?
The result I'm getting now is a mix of found and new.

Thank you
David
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Changed formula to : =IF(ISNA(VLOOKUP(H2,Archive!K:K,1,FALSE)), "New", "Found")

and worked.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top