Search in Excel Using C# and VB.NET
The following example shows how you can search text in a spreadsheet file with C# and VB.NET using the CellRange.FindText
method.
The example will display all the occurrences of searched text in the targeted Excel column.

using System;
using GemBox.Spreadsheet;
class Program
{
static void Main()
{
// If using the Professional version, put your serial key below.
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
var workbook = ExcelFile.Load("%InputFileName%");
var worksheet = workbook.Worksheets[0];
var searchText = "Apollo";
var range = worksheet.Columns[0].Cells;
while (range.FindText(searchText, out int row, out int column))
{
var cell = worksheet.Cells[row, column];
Console.WriteLine($"Text was found in cell '{cell.Name}' (\"{cell.StringValue}\").");
range = range.GetSubrangeAbsolute(row + 1, 0, worksheet.Rows.Count, 0);
}
}
}
Imports System
Imports GemBox.Spreadsheet
Module Program
Sub Main()
' If using the Professional version, put your serial key below.
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
Dim workbook = ExcelFile.Load("%InputFileName%")
Dim worksheet = workbook.Worksheets(0)
Dim searchText = "Apollo"
Dim range = worksheet.Columns(0).Cells
Dim row As Integer, column As Integer
While range.FindText(searchText, row, column)
Dim cell = worksheet.Cells(row, column)
Console.WriteLine($"Text was found in cell '{cell.Name}' (""{cell.StringValue}"").")
range = range.GetSubrangeAbsolute(row + 1, 0, worksheet.Rows.Count, 0)
End While
End Sub
End Module
See also
Next steps
Published: December 13, 2018 | Modified: December 19, 2022 | Author: Mario Zorica