Thread: Find a variable
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Find a variable

The exact variable '&5050' does exist in column A . even expanding the
selection to search in all the cells seems to not work. Neither does just
searching for part.

"stanshoe" wrote:

Ben-

Your code seems to works fine as long as the five character string "&5050"
exists in column A. You get the 'Object variable or With block not set'
error when Find does not return any values. VBA generates the error because
there is no cell referece for it to activate. You shold get the same error
when "itemn" is set to any string that does not exist in Column A.

The "Find" is set to look only at the whole string. If you want to find the
substring "&5050" in one of the cells, you should set Look At value.
to "LookAt:=xlPart"

Stan Shoemaker
Palo Alto, CA



"ben" wrote:

I am simply trying to find a user-input variable on the worksheet.

Dim itemn As String
itemn = "&5050"
Columns("a:a").Select
Find(What:=itemn, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False).Activate

this code always returns the compiler error 'Object variable or With block
not set.'
This is the entire code. I do not recieve the error if use a set value in
place of 'itemn'. I also do not recieve the error if I do not set 'itemn' to
a value
anyone able to tell me why this happens???
thanks