+ Reply to Thread
Results 1 to 19 of 19

instr function if loop to find data

  1. #1
    Forum Contributor
    Join Date
    12-20-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    116

    instr function if loop to find data

    I have cells with a string which looks like

    11.25X2.5X11 abcd efgh hot (1000B)
    11 X2 X10 hot qwerty poiuy (2000B)
    10X2,5X11,25 ghjk hot lkjh (2000B)

    The above strings are in column f2, f3 and f4 and so on

    I want to have an if loop which can look for within f2:f25000
    for string which have three "X" in the cell and the word/string HOT, because that seems like the only filtering criteria that would work (because of inconsistent spaces before and after X imo).

    I am trying to use :
    Please Login or Register  to view this content.
    How can I modify this for it to do what I want, or some other better way of doing it?
    Any suggestions.
    Last edited by diyVBA; 03-02-2020 at 04:22 PM.

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

    Re: instr function if loop to find data

    Are you sure you want to filter for 3 "X"?
    None of your sample has 3 "X"... it it's 2 "X" replace 3 with 2 in code posted below.

    At any rate, you can do something like below...
    Please Login or Register  to view this content.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Forum Contributor
    Join Date
    12-20-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    116

    Re: instr function if loop to find data

    Apologies, I have two X and not three.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,760

    Re: instr function if loop to find data

    How about
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: instr function if loop to find data

    Try
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: instr function if loop to find data

    All the Methods I have seen above will be Slow.

    Try something along these lines. [ I will work on the code after I post this pseudo code. ]

    Use a formula in a n Empty Column to flag your column with "#N/A"

    Select all errors in column F using Select Special.

    Loop through the Selected Cells and use

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 03-02-2020 at 05:22 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,465

    Re: instr function if loop to find data

    Some questions about your data for clarification...

    1) Are your X's always upper cases X's ?

    2) Can the test portion of your cell values ever contain a word with an X in it (such as "XL" or "Exec")?

    3) Are your X's always surrounded on both sides by either digits or spaces?

    4) is the word "hot" always lower case?

    5) Can the test portion of your cell values ever contain the letters "hot" (such "shotput")?

    6) Is the word "hot" always always surrounded by spaces (unless located at the end of the text) or could it appear next to punctuation (period, comma, dash, parenthesis, etc.)?

  8. #8
    Forum Contributor
    Join Date
    12-20-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    116

    Re: instr function if loop to find data

    1) yes always, but I would also want to have something which can take lower case.
    2) Yes WAX
    3) Yes
    4) can be upper or lower case.
    5) yes hotline (but I dont want that).

    This is a really good question
    I found something :
    15X 15 PRT WAX PAPER HOTLINE (2000B)
    This has X in WAX which would mess the logic since I don't want it considered, I want X only when it is between spaces and numbers not followed by an alphabet.


    6) usually surrounded by spaces but can also be followed by characters ex- hotline, usually always starts with space.
    Last edited by diyVBA; 03-02-2020 at 05:27 PM.

  9. #9
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,465

    Re: instr function if loop to find data

    Assuming the two X's always appear before the work "hot", give this macro a try...
    Please Login or Register  to view this content.
    Note: The word "hot" appears to sometimes have non-breaking spaces (ASCII 160) around it... my code accounts for that.

    EDIT NOTE: I made a minor but significant change to my code 19 minutes after I posted it, so if you copy/pasted my code earlier than that, you should redo the copy/paste.
    Last edited by Rick Rothstein; 03-02-2020 at 05:51 PM.

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

    Re: instr function if loop to find data

    2nd one from your initial post.
    11 X2 X10 hot qwerty poiuy (2000B)

    Does this count as meeting your criteria? If it does... here's another approach.
    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: instr function if loop to find data

    Edited after Post# 8

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 03-03-2020 at 04:34 PM.

  12. #12
    Forum Contributor
    Join Date
    12-20-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    116

    Re: instr function if loop to find data

    Quote Originally Posted by Rick Rothstein View Post
    Assuming the two X's always appear before the work "hot", give this macro a try...
    Please Login or Register  to view this content.
    Note: The word "hot" appears to sometimes have non-breaking spaces (ASCII 160) around it... my code accounts for that.

    EDIT NOTE: I made a minor but significant change to my code 19 minutes after I posted it, so if you copy/pasted my code earlier than that, you should redo the copy/paste.
    I can also have "hot" or "HOT" appearing before X.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: instr function if loop to find data

    Reg your message.
    See if this is how you wanted, otherwise I need to see your workbook with the result that you want.
    Please Login or Register  to view this content.
    Last edited by jindon; 03-17-2020 at 07:07 PM.

  14. #14
    Forum Contributor
    Join Date
    12-20-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    116

    Re: instr function if loop to find data

    It works my dataset has only uppercase HOT.
    Last edited by diyVBA; 03-18-2020 at 12:04 PM.

  15. #15
    Forum Contributor
    Join Date
    12-20-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    116

    Re: instr function if loop to find data

    It works, apologies.
    My dataset only has Uppercase HOT.

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: instr function if loop to find data

    OK,
    If you happened to have both, easiest way is to add one line in bold
    Please Login or Register  to view this content.
    But it also accepts small "x".
    If you have problem, just post back.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    And your other thread as well.

  17. #17
    Forum Contributor
    Join Date
    12-20-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    116

    Re: instr function if loop to find data

    It missed these values:

    7 X 1 1/2 X5 HOT DOG SLEEVES G.PROOF
    FOIL HOT DOG 7X1.5X5.5 (1000/BOX)
    FOIL HOT DOG 7X1.5X5.5 (1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1,25X7,5(1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1.25X7.5 (1000/BOX)
    MANCHON HOT DOG GENERIQUE 3.5X1.25X7.5 (1000/BOX)


    Code I am using:

    Please Login or Register  to view this content.

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: instr function if loop to find data

    1) Don't send Visitor Message or PM asking Excel question.
    2) code was looking HOT after 2 Xs, so change to
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    12-20-2019
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    116

    Re: instr function if loop to find data

    Thanks Jindon.

    This works!!

+ 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. [SOLVED] Does not cosistantly find a text string using "InStr" function
    By Bobbbo in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-21-2016, 08:37 PM
  2. Using Find or some other InStr like function with an if and formula.
    By Hyflex in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-02-2015, 11:15 AM
  3. [SOLVED] Find function in nested loop breaking down - not on first time through loop
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-14-2014, 09:32 AM
  4. Find function in nested loop breaking down - not on first time through loop
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2014, 04:59 PM
  5. InStr function doesn't find specific text, but finds any text in column and runs code
    By mikey3580 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-27-2014, 03:50 AM
  6. [SOLVED] If Instr - find last row of data above and delete everything in between
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2013, 03:54 PM
  7. For Exit Loop in instr function
    By drcheaud in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2011, 03:24 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