+ Reply to Thread
Results 1 to 7 of 7

Find Next Function with two criteria Help

  1. #1
    Registered User
    Join Date
    11-13-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    3

    Find Next Function with two criteria Help

    Hello All,


    First of all sorry if this is answered somewhere already, but I didn't know exactly how to word it.

    I am an Engineering Intern that has somehow been tasked with writing Excel Macro for the last month. I've taught myself quite a lot so far but cant figure this one out.

    The first part of the macro needs to search Column Z for the next cell that is not blank or contain a value of 12 in it and then select it. (I.E. a cell contain a value of 8 or 4.2)

    The next part of the macro needs run a goal seek function changing column X until Column Z is 12

    Then End itself when all of Column Z is either blank or 12


    I have written This code so far and it works perfectly except it checks every single row. Which is super slow since there are currently 75500 rows at the moment and will only increase over the years.
    Please Login or Register  to view this content.
    My theory for writing it like this was to hopefully speed up the checking process before goal seek was used. but it is still very slow. ( I know the goal seek part will have to be slow no matter what)

    This code runs when the file is saved and that will only happen if someone updates a value which will change minimum 27 rows and maximum 2145 rows, So the bulk of the 75500 rows will not need to be looked at before saving. (Which I can't seem to avoid)

    Any help or lessons would be greatly appreciated, I'm a quick study most of the time, but I can't find any info on this one to study unfortunately.
    Last edited by wlyon; 11-13-2015 at 05:55 PM.

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Find Next Function with two criteria Help

    Try this...adding Application.ScreenUpdating = True and Application.ScreenUpdating = False like so...
    Please Login or Register  to view this content.
    It might help a little bit.
    I have a question though, you have a If Then statement, but after the Then it goes straight to Else. Usually there is something in between.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    11-13-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    3

    Re: Find Next Function with two criteria Help

    I messed around with Screen Updating and Automatic and Manual Calculations this morningand it shaves a few minutes off the 6.25 hours roughly. But it will probably end up being used (anything helps)

    I wrote the if statement that way hoping it would speed up the process (If the cell was blank or equal to 12 it would simply move on to he next row faster before calling on the Goal Seek) it shaved off a few minutes but if I only need to it change 27 cells I can't have it check all 75500 before it saves the file.

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Find Next Function with two criteria Help

    Wow, over 6 hours! I'm not sure I know of a way to make it quicker. Hopefully someone else with more knowledge will have a solution. Oddly though, I would think that with only 75500 checks it wouldn't take that long at all. Have you tried adding Exit Sub after Then and before Else? Hmm....maybe change your code to this instead....
    Please Login or Register  to view this content.
    Edit* Not sure if this code will work at all...in my head it works perfectly.
    Last edited by gmr4evr1; 11-13-2015 at 05:46 PM. Reason: Added edit

  5. #5
    Registered User
    Join Date
    11-13-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    3

    Re: Find Next Function with two criteria Help

    Tested it and it has a Else without IF Error

    Currently I've changed it up and it is as follows, added the screen updating and manual calculations, along with a small edit some suggested to keep the range moving when new rows are added

    Please Login or Register  to view this content.

    And yes it took over 6 hours yesterday, granted I'm ona i5 processor with minimal ram but the file size is massive and X actually changes 6 different columns and those six columns are all in column Z so it's a lot to go through which is why I was hoping to simply skip all the cells that didn't need fi

  6. #6
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Find Next Function with two criteria Help

    Something with that Then Else just isn't sitting right with me. Did you try adding Exit Sub after the Then and Before Else? Normally, at least from what I have seen, with an If Then, there is always something after the then and before else. It this Then do this, Else do that. The way yours is written its doing If Then Else, and has me baffled.

    Edit*Actually, I've gotten myself so mixed up I'm not even sure adding the Exit Sub is correct.
    Last edited by gmr4evr1; 11-13-2015 at 06:11 PM. Reason: Added Edit

  7. #7
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Find Next Function with two criteria Help

    This code looks better and does the same I think:
    Please Login or Register  to view this content.
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

+ 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] Find array based on specific criteria to use in SUMPRODUCT function
    By cfrae84 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-10-2015, 09:08 AM
  2. Replies: 3
    Last Post: 02-02-2015, 10:30 AM
  3. [SOLVED] Find a number closest to 30 in a range with one more criteria (criteria includes text)
    By Sarangsood in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-22-2013, 01:16 PM
  4. Replies: 4
    Last Post: 09-18-2012, 10:54 AM
  5. Replies: 6
    Last Post: 07-09-2012, 11:06 AM
  6. function to find out count based on criteria.
    By arnab0711 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-30-2011, 06:45 AM
  7. Find function with additional search criteria
    By Neil07979 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-02-2009, 10:38 AM

Tags for this Thread

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