xlValues vs xlFormulas

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

xlValues vs xlFormulas

Post by jstevens »

I don't understand why the search works when I use "xlFormulas" but not "xlValues". Row three contains values no formulas. The code searches Row 3 for the search criteria.

Code: Select all

Sub TestIt()

strSearch = "Source"

With Sheets("Sheet1").Rows("3:3")
    'Set c = .Find(strSearch, LookIn:=xlValues)        'Does not work
    Set c = .Find(strSearch, LookIn:=xlFormulas)       'Works
    
    If Not c Is Nothing Then
        Msgbox "Found in Cell " & c.Address
        
    Else
        Msgbox "not Found"
    End If

End With

End Sub

Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: xlValues vs xlFormulas

Post by HansV »

I can't reproduce the problem; could you attach a sample workbook? Thanks!
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: xlValues vs xlFormulas

Post by jstevens »

Hans,

I have attached a sample file.
Sample.xlsm
Regards,
John
You do not have the required permissions to view the files attached to this post.
Regards,
John

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: xlValues vs xlFormulas

Post by HansV »

If I uncomment the line

'Set c = .Find(strSearch, LookIn:=xlValues)

and comment out the line

Set c = .Find(strSearch, LookIn:=xlFormulas)

the code still finds the string in cell A3. Have you tried it in your sample workbook?
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: xlValues vs xlFormulas

Post by jstevens »

Hans,

I did test on both prior to posting the sample file and the xlValues did not find the string in cell A3. I am using Excel 2007.

I just tried it with Excel 2010 and it worked just fine. It appears to be an Excel 2007 challenge.

Thanks for taking a look,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: xlValues vs xlFormulas

Post by HansV »

That must be it. Excel 2007 is a failure in so many ways... :sad:
Best wishes,
Hans

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: xlValues vs xlFormulas

Post by chamdan »

Hans,

By curiosity, I wanted to see what would happen since I have Excel 2007 and it worked perfectly. Here below is the result:
[img]
MWSnap143.jpg
[/img]

Chuck
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: xlValues vs xlFormulas

Post by HansV »

Thanks for testing. I wonder why it doesn't work for John Stevens...
Best wishes,
Hans