find whole words in excel

M

Meena Chidambaram

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
 
R

Raffaele Tesi

the .find method signature has more then one parameter (all optional).
Look at this url for some example: 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)
 
S

Saumya Negi

Though it's too late for the reply, It could help others in future:
With reference to 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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top