View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika[_2_] Dick Kusleika[_2_] is offline
external usenet poster
 
Posts: 66
Default Using VB to search for a value within one column

Hcoms

How can you search for a value in a sheet while only looking in one
column? I use the below code to use the find feature but it searches all
cols.

ws.Cells.Find(What:="*" & ExcelSearch & "*", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate


ws.Columns(1).Find (etc...

just use the Find method on whatever range you want to search and it will
search only that range. ws.Cells means every cell on the worksheet.


I wish to search and then display all sheets that have a value in it (
i.e. test) I have done the code for looping through a number of workbooks
and then all the worksheets . However what is the best way to check for a
value in a sheet. Is it the code above? And if so how do you prevent the
search finding the values more than once? I presently compare row numbers
, i.e. if the last row where the value was found is greater or equal to
the new found value then it must be starting at the top of the page again.


If you're limiting your search to one column, the rows thing would work. I
usually use the Address property as described here

http://www.dicks-blog.com/excel/2004...nd_method.html

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com