+ Reply to Thread
Results 1 to 9 of 9

Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

  1. #1
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    Hi all,

    Please take a look at my attached spreadsheet.

    I need to select 50 of the records that are marked Paid in column EE, by clicking the corresponding cell in column EG - I have already selected 48 (marked RK) and tallied in cell EN2. The macro would then randomly select 13 of the remaining Paid records and mark them RD.

    However, the value in column EC should be greater than 10.00 in order for that record to be randomly selected, and only if there are not enough records satisfying that condition would other records (i.e., whose value in column EC is less than or equal to 10.00) should be selected in order to reach the required randomly selected 13 records.

    Any help, please?

    Thank you,
    Gos-C
    Attached Files Attached Files
    Using Excel 2010 & Windows 10
    "It is better to be prepared for an opportunity and not have one than to have an opportunity and not be prepared."

  2. #2
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    Hi Gos-C,

    Before trying to do this in a macro, I thought I'd try with a formula or two. If you have a look at columns EH:EJ, you will see that I have the 13 RDs noted.

    Note: I had to tweek EC6 so that I had more than 13.

    I haven't applied my mind to what to do if you have less than 13 yet - that is much more complicated.

    Gos-C P76401083_01Jan201531Mar2015.xlsm

    Is what I have done on the right track?

    I hope this helps, please let me know!

    Regards,

    David

    If this has been of assistance, please advise. A little thanks goes a long way.
    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".

    If several people have responded, when you reply please make it clear WHO you are responding
    to by mentioning their name.

  3. #3
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    Hi David,

    Thank you for your kind response.

    The following is the current macro that performs the random selection:

    Please Login or Register  to view this content.
    What I need is this:

    Modify the code so that records with value 10.00 or less in column EC are selected only if no other records with value greater than 10.00 in column EC are available in order to get the required number of RD records.

  4. #4
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    Hi Gos-C,

    I can see that you are far more advanced than I am with VBA code, and I struggled to see what was going on, but here is a clue.

    I did two things with you code -
    1. I stopped the macro which fired every time I clicked in column "EG". It was driving me nuts! Just an Exit Sub line at the beginning.
    2. I made some changes to the Random macro so that it only selected the >10 values. (It was not looking for that and including some values < $10 when there were values over $10 not getting the RD flag. I just made the array from "EC" instead of "ED" and added a condition for >$10.

    I couldn't work out why the macro behave when you changed some parameters. For example, if you selected an amount in RD_REQUIRED which was less that the "qualifying records" in worked correctly, but if you enter, say, 16 - the thing puts "RD" into every cell. This is obviously the scenario that requires selecting some values less than $10.

    I have included a macro (RANKSEL) in Module1. It receives the number of value to find < $10. (I manually entered c=3)
    It then looks at those records that are less that $10 and uses the RANK function to pick up the highest values.

    I write the result into columns EH:EI then clear them when done.

    This may be clumsy, but hopefully you will find something to use.



    I hope this helps, please let me know!

    Regards,

    David

    If this has been of assistance, please advise. A little thanks goes a long way.
    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".

    If several people have responded, when you reply please make it clear WHO you are responding
    to by mentioning their name.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    Hi David,

    Thanks again for taking the time to delve deeper into the code to see how it was working and try to figure out how to get it to do what I need it to do.

    I did not write that code - are you kidding me. That is too complex and advanced for me. DonkeyOte, one of the forum moderators, wrote it for me some years ago.

    I am reviewing what you posted and will get back to you later.

    Cheers,
    Gos-C

  6. #6
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    Hi Gos-C,

    Too cold to be out on the farm today, so I thought I'd try to delve into the code you have been given.

    GOOD NEWS - I found the culprit!

    I've added one line of code - If dblMax = 1 Then dblMax = 0.999999999. That stopped the thing from writting RD to every cell if you only had, say 12 values which qualified.

    I left the rest of the code alone, and added a small IF statement down the bottom which looks to see how many have been selected, and if it needs some more, it calls the little routine I sent you yesterday.

    Gos-C Test 3.xlsm

    I hope this helps, please let me know!

    Regards,

    David


    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".



  7. #7
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    WOW! This is great news! David, you're the best. You made my day.

    I found what seems to be a bug, but I haven't been able to fix it. When I changed the required RD to 16, only 4 additional RD's are marked (the 20th, 19th and the two 17ths - the 16th is not marked) even though the rdDiff is 5.

    Also, I modified the line for the ranking as follows:

    Please Login or Register  to view this content.
    Wonderful! I will like to buy you a drink.

    Gos-C
    Last edited by Gos-C; 07-05-2015 at 09:38 AM.

  8. #8
    Forum Contributor
    Join Date
    09-19-2004
    Location
    Canada
    Posts
    408

    Re: Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    Hooray! I fixed the bug.

    I added the COUNTIF function to break the tie.

    I changed this:

    Please Login or Register  to view this content.
    to this:

    Please Login or Register  to view this content.
    David, thanks a million! Let me know how I can buy you a drink. I am very grateful for your help.

    Cheers,
    Gos-C

  9. #9
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Select Only If No Other Cell is Greater Than X and All Other Conditions are Met

    Hi Gos-C,

    You're very welcome! Thanks for the Rep. Just your enthusiastic appreciation is thanks enough. Since there are a lot of miles between us, sitting down for a cup of coffee or something is a little difficult.

    All the best - I enjoyed the challenge! I think I learnt a lot from the code DonkeyOte provided.

    David

+ 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. running total with conditions H3 = H2 + G3 if H2 greater than 0 etc.
    By rkobeyer in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-10-2013, 02:40 AM
  2. [SOLVED] IF Function with greater than 51 conditions?
    By jivemario in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-31-2012, 02:44 PM
  3. Coding for comparing sections of columns for greater than/less than conditions
    By xburbx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2010, 10:52 PM
  4. Select last of series greater than 0
    By czar in forum Excel General
    Replies: 4
    Last Post: 05-16-2009, 03:35 PM
  5. Select last cell containing data greater than 0
    By tanewha69 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2006, 07:52 PM

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