+ Reply to Thread
Results 1 to 12 of 12

Find Method - can't get LookAt:=xlWhole to work

  1. #1
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2013
    Posts
    142

    Find Method - can't get LookAt:=xlWhole to work

    Below is my snippet of code. When I run the routine it doesn't match the entire cell contents, it will find partial matches. You'll also notice in the code that some of the parameters (including LookAt) did not auto-capitalize. I'm not getting an error message, but the Find method just isn't working the way I'm needing any to. Any advice?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Find Method - can't get LookAt:=xlWhole to work

    Have you considered using Application.Match?
    Please Login or Register  to view this content.
    By the way, the arguments of a method don't autocapitalze.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2505
    Posts
    2,790

    Re: Find Method - can't get LookAt:=xlWhole to work

    Without seeing a worksheet I couldn't say, but the not capitalizing doesn't mean anything. I usually capitalize mine because I have noticed sometimes it doesn't and I'm just picky.

    I wrote the code below and didn't capitalize lookin or lookat and as you can see LookIn changed but lookat didn't. The code works just fine.

    If you don't want to take Norie's suggestion then post a workbook.

    ViewPic


    Please Login or Register  to view this content.
    EDIT: Very strange, I wrote some other code and didn't capitalize anything, but again lookin changed itself to LookIn but everything else stayed lower case.
    Last edited by skywriter; 01-07-2016 at 05:15 PM.

  4. #4
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2013
    Posts
    142

    Re: Find Method - can't get LookAt:=xlWhole to work

    Thanks for the reply Norie. I haven't used Application.Match before. I'm kind of following along with what you have there, but not entirely. My purpose for this section of my code is a validation check to make sure the user doesn't input duplicate data. So, if Me.CourseText.Value already exists in column B the user will get a message box asking if they want to overwrite the existing data in the row that the course exists. With all that said, help me understand what the variable Res actually represents in your code. Also, am I correct that in your code the variable rFound would be the address that a match was found?

  5. #5
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2013
    Posts
    142

    Re: Find Method - can't get LookAt:=xlWhole to work

    Even with Norie's example I would still like to determine what is causing the problem with the Find method in case I run into it in the future. I've attached my workbook. I appreciate the assistance.
    Attached Files Attached Files

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Find Method - can't get LookAt:=xlWhole to work

    In the code I posted if the value in Me.CourseText is found in column 2 Application.Match will return the row number where it's found, if it's not found then it will return an error.

    If a match is found the variable rFound would be set to refer to the cell the match was found in.

    I included it because I wasn't sure what you were going to do with rFound in the rest of your code, if you are only trying to check for duplicates you don't really need it.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Find Method - can't get LookAt:=xlWhole to work

    Just noticed there's a problem with your code.

    In the If statement if rFound is Nothing rFound.Offset(0,-1).Value will cause an error and since you have On Error Resume Next execution will skip to the message box, so the Find might not be the problem.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2013
    Posts
    142

    Re: Find Method - can't get LookAt:=xlWhole to work

    Ok. I think I'm following along. So taking your code to the next step that I'd need it for, if a match is found I can have a message box pop up asking if the user wants to overwrite the existing row. If they select yes I can us the Res variable as the row number and start doing a .Cells(Res,1).Value = Me.TextBox.Value, .Cells(Res,2).Value = Me.Textbox.Value, etc. etc., correct?

    Edit: By the way, I'm not asking you to write the code for me, I'm just getting confirmation before I dive in.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Find Method - can't get LookAt:=xlWhole to work

    Yes, you can use Res for the row to write the data to.

  10. #10
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2505
    Posts
    2,790

    Re: Find Method - can't get LookAt:=xlWhole to work

    Just out of curiosity, in the file you attached you had testing twice in column B.

    So if you were trying to see if Brand B and testing is a duplicate, then wouldn't you find the testing in B3 and your code would look at A3 see Brand A and therefore not see Testing and Brand B as a duplicate, but it does exist in the row below?

    I admit I haven't studied all your code so maybe it's in there somewhere.

  11. #11
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2013
    Posts
    142

    Re: Find Method - can't get LookAt:=xlWhole to work

    Ahh haa! I believe you found the problem Norie. My intent of the On Error Resume Next was to skip the error when no duplicate was found (rFound = Nothing). I overlooked that it would skip to the msgbox.

    The Application.Match is definitely the route to go. I appreciate your help.

  12. #12
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2013
    Posts
    142

    Re: Find Method - can't get LookAt:=xlWhole to work

    skywriter: Go point, I wasn't thinking that the Find method or Application.Match would stop after the first duplicate in column B is found regardless if column A is a duplicate as well. I'm thinking now that a loop would probably be the better approach for me. This has been a prime example of me thinking I knew more than I actually do.

    I really appreciate both yours and Norie's help on this. You both have educated me not only on actual VBA coding but on really thinking out the process. I'm going to mark the thread as Solved since the issue described in the original request has been resolved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro - Find and Replace - LookAt Issues
    By drewmey in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 10-07-2014, 04:42 AM
  2. [SOLVED] Find Method Doesnt Work
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-30-2013, 09:56 PM
  3. [SOLVED] lookat whole
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2012, 06:10 AM
  4. GetObject method not work after Call Shell Method
    By ben in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-21-2006, 11:50 AM
  5. [SOLVED] How do I restore the LookIn, LookAt, SearchOrder in FIND
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-10-2005, 07:41 PM
  6. Why QUIT method doesn't work after COPY method?
    By surotkin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2005, 11:32 AM
  7. Replies: 10
    Last Post: 07-09-2005, 01:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1