+ Reply to Thread
Results 1 to 15 of 15

For Each with Find and WildCard

  1. #1
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    For Each with Find and WildCard

    Please Login or Register  to view this content.

    I am using this code to check if data in a list is found in another list.

    i now need to reverse this and have it check the other way around.

    My problem is that when I simply change sheet names and ranges everything comes up as not found.
    I think this is due to the data on ws1 containing extra text/numbers than what is being searched for.
    In this function we take care of that with the LookAt argument.

    What I was thinking is finding a way to put in the For Each argument a wildcard. So yes I am looking for v (value) but I need to find a specific part of that (a 5 digit number) on the other sheet (because it only contains the numbers.)

    It there a simple way to alter this code slightly to obtain the results I am looking for, and if not then how should I change this?



    Please Login or Register  to view this content.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: For Each with Find and WildCard

    Maybe if you trim each range with the Worksheet Function then split and check each part from LBound to UBound then you will get a match.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: For Each with Find and WildCard

    Hi cwhite86.

    The .find syntax can be very frustrating at times.

    Your code follows exactly as you wrote it:
    Please Login or Register  to view this content.
    I have not run your code, since you did not provide a sample workbook.

    My speculation is that your problem is with the myRange object. When declaring the object, you probably also need to specify a Sheet.

    For example:
    Please Login or Register  to view this content.
    Additionally, the 'With' syntax is very useful if used properly. In many cases it gives a false sense of security, mostly because of a missing DOT '.' Even though the syntax is very efficient, I try to avoid it because it causes many errors that are very difficult to find and debug.

    I hope this helps.

    Lewis

  4. #4
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: For Each with Find and WildCard

    Sorry for not posting a book. Here is one.

    This is a sheet that will be used in an office setting to validate physical inventory (mapped out on the All Warehouses Tab)
    against what our computer Inventory says we should have (dubbed INV Master on this sheet.)
    The INV Master sheet is populated by a copy and paste off the system.


    I have used buttons in this case to help those who aren't as familiar with excel to navigate through sheets and then work through the currently 4 step process.


    All buttons work as intended. You will see that as you work through the steps the the INV master sheet will highlight yellow products that are found
    and leave in red by default those that are not.

    This is has been a ongoing process and this forum has been a big help throughout the building phases.

    Step 5 will be to highlight the sheets BI2C and BW2C as each number is found on the INV Master Sheet
    This is the opposite of what is happening in MODULE 2. My goal was to take that module and reverse it to perform the needed task.


    My post here was just trying to get the idea of how to do it with one sheet and one column, then go from there. But the whole project would include some 18 sheets similar to BI2C and BW2c.


    I have been receiving help, then breaking down the provided code so that I can understand it enough to fit it for our need.
    I am relatively new to VBA, so its a pretty big learning curve here.


    Thanks
    Attached Files Attached Files

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: For Each with Find and WildCard

    Try this:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: For Each with Find and WildCard

    That highlighted Row 4, and the Title in Row 1.


    I have not used the trim function yet, so I was trying to look through and see if I could figure out why but honestly I am at a loss.


    The goal is to check the numbers under each catergory (Range A5:O100 would cover any possible scenario, preferably would ignore rows 1 - 4)



    Not to be a bother, but to help me really learn here could you break down that code so I can see the logic?
    I understand the basic body of the code, though there are several things I haven't used yet.

    I see how the LightUp function is set apart, and how you used Exit Sub to do so.
    LightUp contains the Find function and of course the IF command and the color command.

    The main SUB body above that is establishing the ranges and the trim argument though I don't fully understand what each line is establishing.




    Thanks so much!

  7. #7
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: For Each with Find and WildCard

    Ok, apologies


    that worked fine in the desensitized test book I gave you, but not in the normal one.

    So obviously I missed something in converting it over, I will look into that.


    Thanks

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: For Each with Find and WildCard

    Maybe, if you posted a more relevant sample, I could adjust the code

    Please Login or Register  to view this content.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: For Each with Find and WildCard

    Maybe, if you posted a more relevant sample, I could adjust the code

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: For Each with Find and WildCard

    The issue is in relation to the INVMaster sheet


    The book I gave you had lines that looked like this

    9BHR20002 2BI2C 50818 277.000

    In reality it looks more like this

    9BHR30002 3" 2C Word Stuff 49810 1200.000


    I started picking apart the code to help myself understand it. Let me take a crack at it here

    For r = 5 To wm.Rows.Find("*", , , , xlByRows, xlPrevious).Row
    This line is saying to reference worksheet wm starting with row 5.
    Then it sets up the rules for the Wildcard "*"

    Thats all I get out of that one.


    C = WF.Trim(wm.Cells(r, 1)): A = Split(C)
    Here it identifies C as the above "r" setting and sets the trim argument.
    I do not fully understand the significance of (r, 1) and am guessing that you are splitting that trim in the last part of that.


    I am assuming my problem lies within on of these two lines and how they are telling Excel to trim, split, and where to look.



    Can I get a little light on this?

    Thanks for your time, I will continue googling and troubleshooting



    EDIT

    Sorry I honestly didn't realize changing the wording and spacing would impact that
    Last edited by cwhite86; 02-17-2016 at 02:50 PM.

  11. #11
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: For Each with Find and WildCard

    Here is a book with the changed lines in the INV Master sheet

    The spacing will vary in each line from product to product.
    This isn't a fixed list, this list will change everyday, as does the BI2C and BW2C pages.
    Attached Files Attached Files

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: For Each with Find and WildCard

    This looks to be working:

    Please Login or Register  to view this content.
    Thanks for the rep!
    Last edited by xladept; 02-17-2016 at 03:39 PM.

  13. #13
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: For Each with Find and WildCard

    Works beautifully!

    I didn't even bother testing it on desensitized book, it works in the actual Book!


    So what was the significance of adding er and setting that as the limit in r?


    And no problem on the rep, anyone who takes this much time to help a newbie who is in way over their head deserves more than that.

  14. #14
    Registered User
    Join Date
    11-13-2015
    Location
    Titusville, PA
    MS-Off Ver
    2010
    Posts
    53

    Re: For Each with Find and WildCard

    That solves that for now.

    I am sure I will post when I get to the next step,

    which will be creating a list of all the cells that are not blank and match a given color.

    To google i go, I'll start a new thread if/when I get stumped.

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: For Each with Find and WildCard

    I just did the er assignment because the other wasn't working

+ 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. Find Wildcard, return that Wildcard value?
    By help_me_im_lost in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-08-2014, 01:20 PM
  2. [SOLVED] Find: Using wildcard, but don't replace with wildcard
    By JimDandy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-06-2013, 05:39 PM
  3. Find a folder by its name or wildcard
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 05-17-2010, 05:22 PM
  4. Find with wildcard characters
    By stanleydgromjr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2010, 08:44 PM
  5. Wildcard Find and Replace
    By DaveSmith2020 in forum Excel General
    Replies: 5
    Last Post: 02-16-2009, 12:27 PM
  6. Find Worksheet with Wildcard
    By philwongnz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2006, 11:30 AM
  7. Find wildcard text within a cell
    By indiana1138 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-31-2005, 08: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