what i want to do is from sheet1 col G value to picked and the check in sheet 2 col B if found then populate the col M with same value found under Col C of sheet 2 against col B value and Col N should be populated with Match /Mismatch as per data in Col J and Col M
@MohammedShabbir could you help me with one more query where i need to check the combination of parent and subacc from sheet 1 and if that combination is there then we can add match else mismatch like in output sheet but data to be populated on sheet1 column D
You can check the Parent + SubAcc combination by using a LINQ query and then update the result in Sheet1 Column D.
Read both sheet into datatable then use for each row as datatable
If dtSheet2.AsEnumerable().Any(Function(r) r(“Parent”).ToString.Trim = row(“Parent”).ToString.Trim AndAlso
r(“SubAcc”).ToString.Trim = row(“SubAcc”).ToString.Trim) Then
row(“Result”) = “Match”
Else
row(“Result”) = “Mismatch”
End If
Made this generic, you can change column names in aruguments, if its chaanging going forward.
’
’ Arguments:
’ dt1 (In/Out), dt2 (In/Out) as DataTable
’ parentCol1, subCol1, qtyCol1 (In) As String
’ parentCol2, subCol2, qtyCol2 (In) As String
For Each r1 As DataRow In dt1.Rows
Dim p1 As String = r1(parentCol1).ToString().Trim()
Dim s1 As String = r1(subCol1).ToString().Trim()
' Default if no match found
Dim qty2Value As Object = Nothing
For Each r2 As DataRow In dt2.Rows
Dim p2 As String = r2(parentCol2).ToString().Trim()
Dim s2 As String = r2(subCol2).ToString().Trim()
If String.Equals(p1, p2, StringComparison.OrdinalIgnoreCase) AndAlso
String.Equals(s1, s2, StringComparison.OrdinalIgnoreCase) Then
qty2Value = r2(qtyCol2)
Exit For
End If
Next
' Add or update column in dt1 for Quantity2
If Not dt1.Columns.Contains("Quantity2") Then
dt1.Columns.Add("Quantity2", GetType(Object))
End If
r1("Quantity2") = qty2Value