+ Reply to Thread
Results 1 to 12 of 12

Convert .find code to .find like

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Convert .find code to .find like

    Hi everyone,

    I have a number of lines of .find code in my macro like the following:

    Please Login or Register  to view this content.
    Sometimes the wbNew.Worksheets(1).range("A3").Value does not exactly match the sheet I'm looking in.

    How can I convert this code to look for values similar to what's in A3 rather than looking for an exact match?

    Any ideas?

    Thanks!!

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Convert .find code to .find like

    Try concatenating with wild card operator (i.e. "*") at front and back of string.

    If I understood your requirement right...
    Please Login or Register  to view this content.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,229

    Re: Convert .find code to .find like

    Give me an example of what the similar matches could be please
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Convert .find code to .find like

    Hi CK76

    I tried wildcards on the outside of the entire string but error 91, object variable or with block variable not set. Here's how I put it:

    Please Login or Register  to view this content.
    Any ideas?

  5. #5
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Convert .find code to .find like

    Hi sintek,

    The string could be in the beginning, middle or end of the lookup range. It could have symbols like & as well

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Convert .find code to .find like

    Can you upload sample workbook? Worked fine on my end.

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

    Re: Convert .find code to .find like

    If you are using Find you can specify to look at the whole or part of cell using the LookAt at parameter.
    If posting code please use code tags, see here.

  8. #8
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Convert .find code to .find like

    hi Norie,

    I tried your suggestion but got a script out of range error message. Here's how the line looks:

    Please Login or Register  to view this content.

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

    Re: Convert .find code to .find like

    Adding lookat:=xlPart would not cause a 'subscript out of range' error.

    Is the value in rngC definitely the name of a sheet in Workbooks(2)?

  10. #10
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Convert .find code to .find like

    Hi Norie,

    Yes, the value is definitely in the worksheet name string. For example, rngC could be something like AB Stuff, but in workbooks(2) the sheet name would be ABStuff. Or, rngC would be DCF but in workbooks(2) the sheet name would be DCF Mgmt.

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

    Re: Convert .find code to .find like

    You have to use the exact worksheet name to refer to a worksheet by name, you can't use a partial match, wildcards, like, whatever...

  12. #12
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Convert .find code to .find like

    Ah, that'll do it then. Thx, Norie.

+ 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. Convert Find Parent Cell Macro to Find Dependent Cell
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2016, 07:30 AM
  2. Find and Display results VBA Code - Loop to find all Matches
    By i2rule in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2014, 03:14 PM
  3. Replies: 1
    Last Post: 04-19-2013, 08:30 PM
  4. [SOLVED] How to code the selection.find not to crash when the data to find is blank
    By evertjvr in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-25-2012, 03:04 PM
  5. trouble with vba code for Find, Insert copied cells and find next
    By jgelbach in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-26-2012, 01:45 PM
  6. Put Find code in Loop to find all matches
    By SarahPintal in forum Excel General
    Replies: 4
    Last Post: 02-08-2010, 09:05 PM
  7. code to find, copy and paste until find new, then repeat
    By siddharthariver in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2010, 04:02 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