Mirror

How to search an Excel worksheet for cells with a particular value (Views: 707)


Problem/Question/Abstract:

How to search an Excel worksheet for cells with a particular value

Answer:

If WS is your worksheet:

{ ... }
var
  Rnge: OleVariant;
  { ... }

Rnge := WS.Cells;
Rnge := Rnge.Find('Is this text on the sheet?');
if Pointer(IDispatch(Rnge)) <> nil then
  {The text was found somewhere, so colour it pink}
  Rnge.Interior.Color := clFuchsia;

<< Back to main page