# Find whole words in excel

**URL:** <https://www.ruby-forum.com/t/find-whole-words-in-excel/130437>\
**Category:** Ruby\
**Created:** [February 28, 2008, 7:38am UTC](https://www.ruby-forum.com/t/find-whole-words-in-excel/130437 "2008-02-28T07:38:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![meena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3be4f8/32.png) [@meena](https://www.ruby-forum.com/u/meena)\
**Post date:** [February 28, 2008, 7:38am UTC](https://www.ruby-forum.com/t/find-whole-words-in-excel/130437/1 "2008-02-28T07:38:37Z")

</div>

I am trying to locate a column name in excel and i am using the “find”  
method. But it seems to be doing a partial match (instead of whole word  
match).  
I have two columns in my excel “ParentOrgId” and “OrgId” , when i search  
for “OrgId” it returns the “ParentOrgId” . How can i make it do a whole  
word match so that it returns “OrgId”.

The snippet of code used is given below

equire ‘win32ole’

excel = WIN32OLE.connect(“excel.application”)  
excel.visible = TRUE  
wbook=excel.Workbooks.open(“D:/test.xls”)  
wsheet=wbook.Worksheets(“OrgInfo”)  
rFoundCell = wsheet.Range(“A1:IV1”).Find(‘OrgId’)  
puts rFoundCell.value

---

<div class="post-metadata">

**Author:** ![meena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3be4f8/32.png) [@meena](https://www.ruby-forum.com/u/meena)\
**Post date:** [February 28, 2008, 1:53pm UTC](https://www.ruby-forum.com/t/find-whole-words-in-excel/130437/2 "2008-02-28T13:53:40Z")

</div>

the .find method signature has more then one parameter (all optional).  
Look at this url for some example: [Excel Automation - Ron de Bruin](http://www.rondebruin.nl/find.htm)

A snippet:

With Sheets(“Sheet1”).Range(“A:A”)  
Set Rng = .Find(What:=FindString, \_  
After:=.Cells(1), \_  
LookIn:=xlValues, \_  
LookAt:=xlWhole, \_  
SearchOrder:=xlByRows, \_  
SearchDirection:=xlPrevious, \_  
MatchCase:=False)

---

<div class="post-metadata">

**Author:** ![meena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3be4f8/32.png) [@meena](https://www.ruby-forum.com/u/meena)\
**Post date:** [June 4, 2010, 12:21am UTC](https://www.ruby-forum.com/t/find-whole-words-in-excel/130437/3 "2010-06-04T00:21:36Z")

</div>

Though it’s too late for the reply, It could help others in future:  
With reference to [Ruby on Windows: excel](http://rubyonwindows.blogspot.com/search/label/excel)  
 →   
Loading the Win32OLE Constants section, I could work this out as  
follows:

class XLConst  
end

WIN32OLE.const\_load(excel, XLConst)  
rFoundCell = wsheet.Range(“A1:IV1”).Find(‘OrgId’,  
‘LookAt’=\>XLConst::XlWhole)

Hope this helps, Cheers!
