+ Reply to Thread
Results 1 to 5 of 5

Combination with criteria

  1. #1
    Registered User
    Join Date
    09-10-2014
    Location
    Melbourne, Australia
    MS-Off Ver
    2010
    Posts
    2

    Combination with criteria

    Hello all!

    I'm stuck... lots of searching and lots of dead ends. I'm hoping that someone here can help!
    The macro I'm looking to build has 2 parts to it.

    Here's what I would like to do:

    PART 1 -
    I would like to create a macro that gives me 6 numbers (which range from 1 to 45 and only occur once in the row) with 1 number in each cell.
    The cells are A, B, C, D, E, F.
    I would like the numbers to be printed in ascending order.
    Once it has done this to then print the next combination in the row below. So on and so forth until all combinations have been done.

    i.e.
    B C D E F G
    Row 1 1 2 3 4 5 6
    Row 2 1 2 3 4 5 7

    I know that there are over 5 million different combinations so I have put in some parameters to narrow it down and here is where it gets tricky...

    PART 2 -
    IF the sum of the combination is less than the value in cell H1 OR greater than the value in H2 then I want the macro to NOT print the result otherwise, print the result and move on to the next combination to check that it meets the criteria.

    To add to the confusion...
    IF the sum of the first 2 numbers of the combination is less than the value in cell H5 OR greater than the value in H6 then I want the macro to NOT print the result otherwise, print the result and move on to the next combination to check that it meets the criteria.

    After every line printed onto the sheet, print the next line on the row below.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Combination with criteria

    I would use something like this, it picks a random number from 1 to 45, adds it to a collection. A collection errors if the data is already present, so we cant add 32 twice, so it goes and re-picks

    Please Login or Register  to view this content.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    09-10-2014
    Location
    Melbourne, Australia
    MS-Off Ver
    2010
    Posts
    2

    Re: Combination with criteria

    A little more than that though... i need all 6 picked then the whole combination tested...

  4. #4
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Combination with criteria

    I have got almost to what you want..
    Just select 6 cells and run the macro Named Rand_Nums()


    Please Login or Register  to view this content.
    Conditions...
    Please Login or Register  to view this content.
    Actually the first code runs beautifully but when I insert the conditions it giving errors ...
    I guess... May be you have more realistic values in those cells ..
    So you can give a try to the above condition statement by pasting it in the Original code..
    I hope it works..
    Last edited by Vikas_Gautam; 09-10-2014 at 10:13 PM.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Combination with criteria

    Sorry . .

+ 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. formula needed with a combination of criteria
    By Robert1311 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-24-2014, 08:53 AM
  2. [SOLVED] Best possible combination given limitations and criteria
    By rcoope02 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-18-2013, 04:18 PM
  3. Replies: 2
    Last Post: 10-23-2012, 11:09 AM
  4. Replies: 1
    Last Post: 02-16-2012, 09:57 AM
  5. Meet Combination Criteria and dump data accordingly
    By chrismartinpetty in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2011, 08:15 AM

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