+ Reply to Thread
Results 1 to 18 of 18

Find and Replace with multiple conditions problem.

  1. #1
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Find and Replace with multiple conditions problem.

    Hey all,
    Hopefully someone can help me with this problem I'm having, as I can't seem to find a solution anywhere online or in the help files that works for me. I'm currently trying to write some code that will search a row for a specific string, and once found, will then look at the cell to the immediate left for a different specific string. If it finds both, it will then copy the contents of the cell 2 rows to the left into a different cell on a seperate sheet. This is what I've come up with so far:

    Please Login or Register  to view this content.
    That code will search down the D column for the string "MH" and then check for the string "Available" in the adjacent cell. What I can't figure out is how to properly use the FindNext command to keep searching if it doesn't find the "Available" string in the adjacent cell, until both conditions are met, and then execute the other code.

    Hopefully I've explained it so that other people can understand what I'm trying to do.
    Any help would be greatly appreciated

    Chris
    Last edited by Benisato; 03-12-2010 at 06:06 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find and Replace with multiple conditions problem.

    Try this:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 03-11-2010 at 04:11 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    Hrm, I tried that code in my sheet, and it still always only returns the first MH it finds, even if the adjacent cell doesn't say "Available". It looks like it should work, not sure whats wrong with it.

    Chris

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find and Replace with multiple conditions problem.

    Post up a workbook, make sure it's clear what you want as "results".

    This is set to find and transfer one match. You want it to run and find them all at once?

  5. #5
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    Basically what I'm trying to do is create a Schedule Generator. It works like this, when you run it, it pops up a userform that lists all the employees that work in my department, and it has a dropdown box beside each one. The dropdown box defaults to "Available" to signify that they're available to be slotted into the schedule. If you change the dropdown box to something other than available, it changes the corresponding box in the data sheet. The code then uses the data sheet to find available people and slot them into positions they're trained to do. I'm sure my workbook wont look too pretty to some of you pro's, I'm still new to excel, and trying to push myself to learn more with challenging tasks.

    The part I'm trying to get working now is to get it to fill in the "MH" position on the schedule, with someone who is trained as an "MH", But if the first "MH" isn't available, I want it to select the 2nd one and put that person in that position instead.

    Hope that clarifies things a bit.

    Chris
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    I consider this a minor hurdle, the major hurdle I forsee with this little project is that once I get all off the critical positions slotted into the schedule (MH, QA, and 2 Printers) I want to eventually have it slot in the rest of the available operators into random locations on the schedule

  7. #7
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    Can anyone else possibly help me with this?

    Thanks,
    Chris

  8. #8
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    Nevermind, I figured out the problem,
    Please Login or Register  to view this content.
    Should have been

    Please Login or Register  to view this content.
    Thanks a lot for the help, it is very much appreciated.

    Chris

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find and Replace with multiple conditions problem.

    My bad, that was a rookie error. Sorry about that. I edited the listing in post #2 so that it reads as complete and correct.

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  10. #10
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    Actually, it created a new problem. The code works great as is unless it doesn't find any matches, in which case it should output a textbox that says "No MH Found" but that currently never happens, if it doesn't find anything that matches both criteria, it just does nothing and makes field "B29" blank, any ideas how I can fix that?

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find and Replace with multiple conditions problem.

    I thought that was in there. Please post an updated example book w/macro so I can see that...
    Last edited by JBeaucaire; 03-11-2010 at 03:43 PM.

  12. #12
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    Ok, in this workbook, if you hit the generate schedule button, it will bring up a userform with all the employees. If you change any of them from "available" to anything else, it should exclude them from the schedule. Currently if you change "Connie-Lee" and or "Shannon" from available to something else, it should skip over them and search for a different printer via the Data sheet Column D, if it can't find them, it should then search for a backup, Via the data sheet, Column E, if it can't find one there, it should output a textbox that says "No printer found" same for MH and QA, but once it completes the loop for the primary positions, it never searches for a backup, and never outputs a textbox if it can't find the appropriate people. I hope that explanation made sense.
    Attached Files Attached Files

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find and Replace with multiple conditions problem.

    There's no need for a backup-qa macro, the one macro is supposed to keep looping for you until one is found. If your address the cells directly instead of trying to offset, then you can target the "allocated" message to column C no matter where the QA is found, you know?

    example:
    Please Login or Register  to view this content.


    I've changed all the macros accordingly to demonstrate and simplify.
    Last edited by JBeaucaire; 03-12-2010 at 12:10 AM. Reason: code and sheet removed...see below

  14. #14
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    When I try to run that, I get a Run-time error '6'
    Overflow

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find and Replace with multiple conditions problem.

    On the sheet I uploaded? Please provide more specifics, when an error occurs, DEBUG and report the line of code that stalled, also hover your mouse over all the variables on and near that row to note the current values of those variables. Thanks.

    Meanwhile, I got tunnelvision testing the "no QA" message, so I got that working and forgot to verify the form would find names normally, which it stopped doing. This fix should do that, forgot some periods...pesky little things.

    Example:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    I downloaded your newest sheet, and I get the same error when I try to run it. I just open the file, and click "Generate Schedule" and then leave all the values normal (all employees "Available") and hit the generate button on the userform. I immediatly get an Error: Runtime Error '6': Overflow. When I click debug, it highlights the find section of code in the Find_QA function

    Please Login or Register  to view this content.
    when I hover over the strFind variable, it says strFind = Nothing, which seems normal, and FindString = QA, which also seems normal, I'm not sure why its hanging up, should there be a range attached to the With Sheets("Data").Cells ?

  17. #17
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find and Replace with multiple conditions problem.

    When I open the sheet, click your button and then generate, I get an instant finish with:

    Please Login or Register  to view this content.

    Here's a different syntax for one line, replace all the macros on this line to:

    Please Login or Register  to view this content.
    See if you get better results. It's working as is for me.

  18. #18
    Registered User
    Join Date
    03-10-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Find and Replace with multiple conditions problem.

    That works perfectly! I'm not sure what the difference in syntax was, but that last change made it work exactly they way I wanted, finally. Thanks so much for your help

    Chris

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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