How to update excel cell based on other row

Hi

I want to update IN in 5th column if 2nd column has India in it. Many such rows .
Can we use linq or any other way ?

Hi @S_Nitin

Code:

Dim dataTable As DataTable = DT ' Replace with the name of your DataTable variable

For Each row As DataRow In dataTable.Rows
    ' Check if the 2nd column contains "India"
    If row(1).ToString().Contains("India") Then
        ' Update the 5th column with "IN"
        row(4) = "IN"
    End If
Next

BlankProcess13.zip (165.0 KB)

Hope this helps!!

You don’t need Linq or anything like that for such simple DataTable Manipulations.
Just do this:

  • Read Range your Excel File to be processed
  • Add a “For Each Row in DataTable”
  • Inside the Body add an “IF”
  • The “IF” should be as followed CurrentRow(1).ToString.Contains("India")
  • Then: Update the CurrentRow(4) only if it contains India
  • Write Range back to your Excel