View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
John John is offline
external usenet poster
 
Posts: 2,069
Default Help with .Find Function in code

Have you used Set to assign an object reference to your variable?

something like:

Dim dataCorrWS As WorkSheet

Set dataCorrWS = Worksheets(€śData Corr€ť)

following example finds first instance of search criteria in Col C - change
sheet name as required.

Sub SearchData()

Dim Foundcell As Range
Dim Search As String
Dim InsiteWS As Worksheet

Set InsiteWS = ThisWorkbook.Worksheets("InSite Milestones")


Search = "NY09337C"

Set Foundcell = InsiteWS.Columns(3).Find(Search, _
LookIn:=xlValues, _
LookAt:=xlWhole)


If Foundcell Is Nothing = False Then

msg = MsgBox("Search Value: " & Search & Chr(10) & _
"Found At: " & Foundcell.Address, 64, "Search")

Else

msg = MsgBox("Search Value: " & Search & Chr(10) & _
"Not Found", 16, "Search")

End If

End Sub



--
jb


"Ayo" wrote:

I am trying to use the Find in my code but I am getting a "Object variable or
With block variable not set" error message on the code line below.
dataCorrWS.Range("C2:C" & dataCorrWSlastRow).Find(c.Value,
LookIn:=xlValues).Activate

but another variation of the code:
Worksheets("InSite Milestones").Range("C2:C3000").Find("NY09337C",
LookIn:=xlValues).Activate

works fine. Any ideas.