Here this is input sheet
Here this is lookup sheet
Here based on BLV & 532 fetch its desc (from lookup sheet) and update in input sheet under c_pos_rev_center_cd column
Can we perform a lookup using two columns as here, based on first & second column we need to retrieve 3rd column value. How do we achieve using this VB code shared earlier.
Below code works if the columns names in input & lookup sheet are same.
dt1.AsEnumerable().ToList().ForEach(Sub(row) row(“c_prop_cd”)= If(dt2.AsEnumerable().Where(Function(r) r(“c_prop_cd”).ToString.Equals(row(“c_prop_cd”).ToString) And r(“c_pos_rev_center_cd”).ToString.Equals(row(“c_pos_rev_center_cd”).ToString)).Count<>0, dt2.AsEnumerable().Where(Function(r) r(“c_prop_cd”).ToString.Equals(row(“c_prop_cd”).ToString))(0)(“c_prop_desc”).ToString,row(“c_prop_cd”).ToString))
What if the column names are different like below, will this not work?
This is input sheet
Lookup sheet
Here c_comp_prop_cd of input sheet is equal to c_rev_center_cd of lookup sheet
c_prop_cd of input sheet is equal to c_prop_cd of lookup sheet
c_lms_rev_center_desc need to be fetch & replace c_comp_prop_cd with desc value
Tried with below:
dt1.AsEnumerable().ToList().ForEach(Sub(row) row(“c_comp_prop_cd”)= If(dt2.AsEnumerable().Where(Function(r) r(“c_comp_prop_cd”).ToString.Equals(row(“c_rev_center_cd”).ToString) And r(“c_prop_cd”).ToString.Equals(row(“c_prop_cd”).ToString)).Count<>0, dt2.AsEnumerable().Where(Function(r) r(“c_rev_center_cd”).ToString.Equals(row(“c_comp_prop_cd”).ToString))(0)(“c_lms_rev_center_desc”).ToString,row(“c_comp_prop_cd”).ToString))
I get Invoke code: Exception has been thrown by the target of an invocation for above code
dt1.AsEnumerable().ToList().ForEach(Sub(row) row(“c_comp_prop_cd”)= If(dt2.AsEnumerable().Where(Function(r) r(“c_rev_center_cd”).ToString.Trim.Equals(row(“c_comp_prop_cd”).ToString.Trim) And r(“c_prop_cd”).ToString.Trim.Equals(row(“c_prop_cd”).ToString.Trim)).Count<>0,dt2.AsEnumerable().Where(Function(r) r(“c_rev_center_cd”).ToString.Trim.Equals(row(“c_comp_prop_cd”).ToString.Trim) And r(“c_prop_cd”).ToString.Trim.Equals(row(“c_prop_cd”).ToString.Trim))(0)(“c_lms_rev_center_desc”).ToString, row(“c_comp_prop_cd”).ToString))