Compare value if matched copy another cell

IFeelYourPain

New Member
Joined
Feb 17, 2015
Messages
17
I have a set up in two different worksheets.

[WS1]
7458 Completed
5487 Not Completed
5687 Completed
1258 Completed


[WS2]
7458
7777
8987
1452
5487
8957


If WS2 has a value in A column that matches the A column of WS1, then I want it to copy the value of Column B in WS1. This needs to be done for multiple instances and pasted into a new worksheet. How can I go about doing this?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hello,

can be achieved by formula:

In WS2 (assumed 7458 is in cell A1), cell B1, enter this formula =IF(ISERROR(VLOOKUP(A1,Sheet1!A:B,2,0)),"",VLOOKUP(A1,Sheet1!A:B,2,0)) and copy down as far as required.

Is this acceptable?
 
Upvote 0
Hello,

VB solution

Code:
Sub CHECK_VALUES()
    With Sheets("Sheet2")
        .Range("B1").Formula = "=IF(ISERROR(VLOOKUP(A1,Sheet1!A:B,2,0))," & """""" & ",VLOOKUP(A1,Sheet1!A:B,2,0))"
        .Range("B1").Copy Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    End With
End Sub
 
Upvote 0
It created a new column and it says status for the title, but the cells below it are blank.
 
Last edited:
Upvote 0
Actually I got it to work, but is there anyway instead of copying the content, it would instead put y or no if completed or not completed? Sometimes there is also information after completed, so it can't be an exact match. Not sure how to do that?
 
Upvote 0
Hello,

Amending the code previously supplied:

Code:
Sub CHECK_VALUES_1()
    With Sheets("Sheet2")
        .Range("B1").Formula = "=IF(ISERROR(VLOOKUP(A1,Sheet1!A:B,2,0))," & """""" & _
            ",IF(LEFT(VLOOKUP(A1,Sheet1!A:B,2,0),9)=" & """" & "Completed" & """" & "," & """" & "y" & """" & _
       ",IF(LEFT(VLOOKUP(A1,Sheet1!A:B,2,0),13)=" & """" & "Not Completed" & """" & "," & """" & "no" & """" & ",)))"
        .Range("B1").Copy Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    End With
End Sub

Does it work as expected?
 
Upvote 0

Forum statistics

Threads
1,203,347
Messages
6,054,878
Members
444,760
Latest member
TeckTeck

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