Comparing Column:A(Sheet1) with Column:B(Sheet2) and printing the unmatched values in Column:B(Sheet2)

Jabes7

New Member
Joined
Jul 13, 2012
Messages
12
Hi to all Brainee Folks,

I have a piece of VBA code which compares Column:A(Sheet1) with Column:B(Sheet2) and prints the unmatched values in Column:B(sheet2). I used resize to fetch the entire row of Sheet1( unmatched values) and writes in Sheet2.

Now my Immediate requirement is, i need to check for condition on Column:C(Sheet1) if the row value is 'Yes', it can fetch the unmatched values of appropriate rows of Sheet1 and can write in Sheet2. Kindly Help

Code:
Sub NotFoundList()

    Dim AWF As WorksheetFunction: Set AWF = WorksheetFunction
    Dim cell As Range
    Dim s1LastRow As Long
    Dim s2LastRow As Long
    Dim s3RowCount As Long
    Dim S2RowCount As Long
    Dim s3 As Long


    With Sheets("Sheet1")
        s1LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    End With


    With Sheets("Sheet2")
        s2LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
        S2RowCount = s2LastRow + 1
    End With


    With Sheets("Sheet1")
        For Each cell In .Range("A1:A" & s1LastRow)
            If AWF.CountIf(Sheets("Sheet2").Range("B1:B" & s2LastRow), cell.Value) = 0 Then
                Sheets("Sheet2").Range("B" & S2RowCount).Resize(, 4) = cell.Resize(, 4).Value
                S2RowCount = S2RowCount + 1
            End If
        Next
    End With
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Now my Immediate requirement is, i need to check for condition on Column:C(Sheet1) if the row value is 'Yes', it can fetch the unmatched values of appropriate rows of Sheet1 and can write in Sheet2. Kindly Help

I'm not sure I follow your new criteria. This tests if the Sheet1.columnC value is "Yes", then tests if the value is unmatched as before.

Code:
    With Sheets("Sheet1")
        For Each cell In .Range("A1:A" & s1LastRow)
[COLOR=#ff0000]            If LCase(cell.Offset(, 2).Value) = "yes" Then[/COLOR]
                If AWF.CountIf(Sheets("Sheet2").Range("B1:B" & s2LastRow), cell.Value) = 0 Then
                    Sheets("Sheet2").Range("B" & S2RowCount).Resize(, 4) = cell.Resize(, 4).Value
                    S2RowCount = S2RowCount + 1
                End If
[COLOR=#ff0000]            End If[/COLOR]
        Next
    End With
 
Upvote 0
I'm thinking along the same lines as AlphaFrog.

Code:
Sub NotFoundList()    Dim AWF As WorksheetFunction: Set AWF = WorksheetFunction
    Dim cell As Range
    Dim s1LastRow As Long
    Dim s2LastRow As Long
    Dim s3RowCount As Long
    Dim S2RowCount As Long
    Dim s3 As Long

    With Sheets("Sheet1")
        s1LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    End With

    With Sheets("Sheet2")
        s2LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
        S2RowCount = s2LastRow + 1
    End With

    With Sheets("Sheet1")
        For Each cell In .Range("A1:A" & s1LastRow)
            If AWF.CountIf(Sheets("Sheet2").Range("B1:B" & s2LastRow), cell.Value) = 0 [COLOR=#ff0000]_
               And cell(, 3).Value = "Yes"[/COLOR] Then
                    Sheets("Sheet2").Range("B" & S2RowCount).Resize(, 4) = cell.Resize(, 4).Value
                    S2RowCount = S2RowCount + 1
            End If
        Next
    End With
End Sub

Hope it helps.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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