Loop, Compare, Match & Total

S.H.A.D.O.

Well-known Member
Joined
Sep 6, 2005
Messages
1,915
Hi everyone,

I will give this request one last try and put it as simply as I can without all the confusing and complicated jargon.
I have the following wheel of 6 number combinations in Cells "B3:G12" in a sheet named "Data".

01 02 03 04 05 06
01 07 08 09 10 11
01 12 13 14 15 16
02 03 07 08 12 13
02 03 09 10 14 15
04 05 07 08 14 15
04 05 09 10 12 13
02 03 04 05 11 16
06 07 08 09 10 16
06 11 12 13 14 15

I want to iterate through ( see the code below ) ALL the 5 number combinations produced from "n" ( "n" = the highest number used in ANY of the 6 number combinations which is 16, so C(16,5) = 4,368 combinations ) and compare each 5 number combination with each 6 number combination in the wheel above.

If at "LEAST" 2 numbers match then add 1 to the 2 if 5 category total ( total to go in Cell "D12" in the sheet named " Statistics" ).
If at "LEAST" 3 numbers match then add 1 to the 3 if 5 category total ( total to go in Cell "D16" in the sheet named "Statistics" ).
If at "LEAST" 4 numbers match then add 1 to the 4 if 5 category total ( total to go in Cell "D19" in the sheet named "Statistics" ).
If ALL 5 numbers match then add 1 to the 5 if 5 category total ( total to go in Cell "D21" in the sheet named "Statistics" ).

If ANY of the 5 number combinations does NOT match ANY of the 6 number combinations with the required scenario of ? if 5, then that 5 number combination is NOT covered for that particular scenario of ? if 5 and therefore 1 ( one ) cannot be added to the respective ? if 5 category total.

That is it in a nutshell really.

I have written the following code which might be of use :-

Code:
Option Explicit 
Option Base 1 
 
Sub Produce_5_Number_Combinations() 
     
    Dim A As Integer 
    Dim B As Integer 
    Dim C As Integer 
    Dim D As Integer 
    Dim E As Integer 
    Dim MinVal As Integer 
    Dim MaxVal As Integer 
     
    Application. ScreenUpdating = False 
     
    MinVal = 1 
    MaxVal = Whatever the highest number In the sheet named "Data" And In the Range "B3:G?" is. 
     
    For A = 1 To MaxVal - 4 
        For B = A + 1 To MaxVal - 3 
            For C = B + 1 To MaxVal - 2 
                For D = C + 1 To MaxVal - 1 
                    For E = D + 1 To MaxVal 
                         
                        *** Code goes here maybe *** 
                         
                    Next E 
                Next D 
            Next C 
        Next B 
    Next A 
     
    *** Output totals For Each category *** 
     
    Application.ScreenUpdating = True 
End Sub
Thanks in Advance.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top