PC Review


Reply
Thread Tools Rate Thread

cell.find not working

 
 
=?Utf-8?B?Tm9lbWk=?=
Guest
Posts: n/a
 
      29th Jun 2007
Hi

For some reason my code is returning the foundcell as true all the time even
though the data is not there. If I do a manual find then it comes back as not
found but with the code it comes back as found which is not correct.

Below is the code I have, if anyone can give me some info on what to do to
fix this probelm.

stVoucherID = Application.Range("A" & dbnum).Value
Sheets(2).Select
Application.Range("F1").Select
Set foundcell = Cells.Find(What:=stVoucherID, After:=ActiveCell,
LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
True)
If foundcell Is Nothing Then
Sheets(3).Select
Application.Range("a1").Select
End if


Thanks
Noemi
 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      29th Jun 2007
What does "stVoucherID" evaluate to ?

NickHK

"Noemi" <(E-Mail Removed)> wrote in message
news:7FDDB662-162A-4D48-9700-(E-Mail Removed)...
> Hi
>
> For some reason my code is returning the foundcell as true all the time

even
> though the data is not there. If I do a manual find then it comes back as

not
> found but with the code it comes back as found which is not correct.
>
> Below is the code I have, if anyone can give me some info on what to do to
> fix this probelm.
>
> stVoucherID = Application.Range("A" & dbnum).Value
> Sheets(2).Select
> Application.Range("F1").Select
> Set foundcell = Cells.Find(What:=stVoucherID, After:=ActiveCell,
> LookIn:=xlValues, LookAt _
> :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
> MatchCase:= _
> True)
> If foundcell Is Nothing Then
> Sheets(3).Select
> Application.Range("a1").Select
> End if
>
>
> Thanks
> Noemi



 
Reply With Quote
 
=?Utf-8?B?Tm9lbWk=?=
Guest
Posts: n/a
 
      29th Jun 2007
Hi Nick
StVoucherID is set as a string and stores numbers a text.

However I worked out my problem, I need to add ActiveSheet before the
Cells.Find as I am working over multiple sheets.

thanks for your help anyway.

Noemi

"NickHK" wrote:

> What does "stVoucherID" evaluate to ?
>
> NickHK
>
> "Noemi" <(E-Mail Removed)> wrote in message
> news:7FDDB662-162A-4D48-9700-(E-Mail Removed)...
> > Hi
> >
> > For some reason my code is returning the foundcell as true all the time

> even
> > though the data is not there. If I do a manual find then it comes back as

> not
> > found but with the code it comes back as found which is not correct.
> >
> > Below is the code I have, if anyone can give me some info on what to do to
> > fix this probelm.
> >
> > stVoucherID = Application.Range("A" & dbnum).Value
> > Sheets(2).Select
> > Application.Range("F1").Select
> > Set foundcell = Cells.Find(What:=stVoucherID, After:=ActiveCell,
> > LookIn:=xlValues, LookAt _
> > :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
> > MatchCase:= _
> > True)
> > If foundcell Is Nothing Then
> > Sheets(3).Select
> > Application.Range("a1").Select
> > End if
> >
> >
> > Thanks
> > Noemi

>
>
>

 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      29th Jun 2007
this works for me if i'm looking for the word test on sheet2. no need to select
the sheet

Sub test()

stVoucherID = "test" 'Application.Range("A" & dbnum).Value
With Sheets(2)
Set foundcell = .Cells.Find(What:=stVoucherID, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=True)
End With
If foundcell Is Nothing Then
Sheets(3).Select
Application.Range("a1").Select
Else
MsgBox foundcell.Address
End If
End Sub

--


Gary


"Noemi" <(E-Mail Removed)> wrote in message
news:A2137820-5A42-40F8-8C65-(E-Mail Removed)...
> Hi Nick
> StVoucherID is set as a string and stores numbers a text.
>
> However I worked out my problem, I need to add ActiveSheet before the
> Cells.Find as I am working over multiple sheets.
>
> thanks for your help anyway.
>
> Noemi
>
> "NickHK" wrote:
>
>> What does "stVoucherID" evaluate to ?
>>
>> NickHK
>>
>> "Noemi" <(E-Mail Removed)> wrote in message
>> news:7FDDB662-162A-4D48-9700-(E-Mail Removed)...
>> > Hi
>> >
>> > For some reason my code is returning the foundcell as true all the time

>> even
>> > though the data is not there. If I do a manual find then it comes back as

>> not
>> > found but with the code it comes back as found which is not correct.
>> >
>> > Below is the code I have, if anyone can give me some info on what to do to
>> > fix this probelm.
>> >
>> > stVoucherID = Application.Range("A" & dbnum).Value
>> > Sheets(2).Select
>> > Application.Range("F1").Select
>> > Set foundcell = Cells.Find(What:=stVoucherID, After:=ActiveCell,
>> > LookIn:=xlValues, LookAt _
>> > :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
>> > MatchCase:= _
>> > True)
>> > If foundcell Is Nothing Then
>> > Sheets(3).Select
>> > Application.Range("a1").Select
>> > End if
>> >
>> >
>> > Thanks
>> > Noemi

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NEED VBA TO SELECT A CELL; NOTE THE CELL VALUE;COPYADJ CELL;FIND CELL VALUE IN A RANGE AND SO ON CAPTGNVR Microsoft Excel Programming 2 8th Jul 2007 04:18 PM
VBA Find and Replace isn't working on apostrophe within cell value Jon Microsoft Excel Programming 2 22nd Jun 2007 04:10 PM
API to find position of active cell no longer working in 2007. GollyJer Microsoft Excel Programming 12 13th Jun 2007 09:29 PM
Loop to find next empty cell to the right not working. Casey Microsoft Excel Programming 3 4th May 2006 03:16 PM
.find with merged cell not working Sunil Patel Microsoft Excel Programming 5 3rd Jul 2005 08:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:10 PM.