View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
damezumari damezumari is offline
external usenet poster
 
Posts: 2
Default Cells.Find problem

I use Excel 2000 and Win2000.

I have two sheets in my workbook. One of the cells on the sheet called
"dummy" has the word "charge" in it.

This code in the click event for a button on the "dummy" sheet, finds
the cell with "charge":

Private Sub CommandButton1_Click()
Dim FoundCell As Range
Set FoundCell = Cells.Find(What:="charge", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False)
If FoundCell Is Nothing Then
MsgBox "Not Found"
Else
MsgBox "Found"
End If
End Sub

However, this code in the click event for a button on my other sheet,
does not:

Private Sub CommandButton1_Click()
Dim FoundCell As Range
Sheets("dummy").Select ' only change from the code above
Set FoundCell = Cells.Find(What:="charge", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False)
If FoundCell Is Nothing Then
MsgBox "Not Found"
Else
MsgBox "Found"
End If
End Sub

What am I doing wrong?