Excel operations to fetch columns

In Excel, First column consists of 3 bananas , 2nd 3 apple and 3rd 3 oranges

  1. Bot should check how many bananas, apples, orange are their? Count it

  2. Add one other fruit name(Mango) at one of the banana place& run , show me the count of mango and banana now

Anyone please help me with code?

Hi @Shravan_Pintu

bananaCount = dt.AsEnumerable().Count(Function(row) row("Column1").ToString.Equals("banana", StringComparison.OrdinalIgnoreCase))
appleCount = dt.AsEnumerable().Count(Function(row) row("Column1").ToString.Equals("apple", StringComparison.OrdinalIgnoreCase))
orangeCount = dt.AsEnumerable().Count(Function(row) row("Column1").ToString.Equals("orange", StringComparison.OrdinalIgnoreCase))

Regards,

@Shravan_Pintu

Input:

image

Output:

image

mangoCount = dt.AsEnumerable().Count(Function(row) row("Fruits").ToString.Equals("mango", StringComparison.OrdinalIgnoreCase))

Input:

Output:

image

Regards,

Here Bot should replace one banana row with a mango & should check the count

@Shravan_Pintu

Try this

Invoke Code:

' Find the first occurrence of "Banana" and replace it with "Mango"
Dim firstRow = (From row In dt.AsEnumerable()
                Where row.Field(Of String)("Fruits") = "Banana"
                Select row).FirstOrDefault()

If firstRow IsNot Nothing Then
    firstRow("Fruits") = "Mango"
End If

Input:

Output:

image

Sequence16.xaml (14.0 KB)

Regards,

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.