I have the following scenario: Excel1
Requestor name : John
Category : light, Internet
Total : 20,36 , 15,54
Excel2
Employee Name : John
Light :
Internet :
I need to search for the requestor’s name in Excel2 under the ‘Employee Name’ column and place the corresponding total values in two different columns: ‘Light’ and ‘Internet’.
Excel 1
For Each excel1Row As DataRow In dt_Excel1.Rows
Dim matchedRow As DataRow = dt_Excel2.AsEnumerable().Where(Function(r) r("Employee Name").ToString().Trim().ToLower() = excel1Row("Requestor name").ToString().Trim().ToLower()).FirstOrDefault()
If matchedRow IsNot Nothing Then
Dim totalValues As String() = excel1Row("Total").ToString().Split(","c)
If totalValues.Length > 0 Then
If excel1Row("Category").ToString().Contains("Light", StringComparison.OrdinalIgnoreCase) Then
For Each value As String In totalValues
If Not String.IsNullOrEmpty(matchedRow("Light").ToString()) Then
matchedRow("Light") = matchedRow("Light").ToString() & ", " & value.Trim()
Else
matchedRow("Light") = value.Trim()
End If
Next
End If
If excel1Row("Category").ToString().Contains("Internet", StringComparison.OrdinalIgnoreCase) Then
For Each value As String In totalValues
If Not String.IsNullOrEmpty(matchedRow("Internet").ToString()) Then
matchedRow("Internet") = matchedRow("Internet").ToString() & ", " & value.Trim()
Else
matchedRow("Internet") = value.Trim()
End If
Next
End If
End If
End If
Next
Actually i forget to tell you that if
Requestor name : John Bell ,then in employee name : value can be John or Bell or John Bell. value can be either full name or firstname or lastname
inside loop use filter datatable on dt with currentrow("Enployee Name").ToString and use contains in column Reqestor Name
Now use lookup datatable and lookup for light and internet and fill the value using assign …currentrow("Light") = value from lookup for lgiht and similarly for internet