Running a Macro Until result Achieved

PM1

Board Regular
Joined
Oct 28, 2005
Messages
192
I have a table shown A2:F18 below that Randomises each of the 4 columns A-D with No's from 1 - 17by pressing F9 - this is done in a the following formula:-

=LARGE(ROW($1:$18)*NOT(COUNTIF(A$1:A1, ROW($1:$18))), RANDBETWEEN(1,18-ROW(A1)))

I have another column F which validates if the row is unique and has no duplicates and shows 1 or 0 and has another long winded formula:-

=IF(A2=B2,0,IF(A2=C2,0,IF(A2=D2,0,IF(B2=C2,0,IF(B2=D2,0,IF(C2=D2,0,1))))))

At the bottom of the table I have a cell that checks if column F = 17, being all unique rows and reports NOT YET or SUCCESS, SUCCESS has not yet been reached and my F9 finger is sore

I need to be able to run this in a Macro until the result is = 17, any ideas?

Excel Workbook
ABCDEFGHI
273415*1***
317181413*1***
411882*0***
5611177*1***
61212185*0***
736212*1***
849139*0***
91810716*1***
101321111*0***
11151356*1***
1285128*0***
1314141514*0***
1457163*1***
15917618*1***
16241017*1***
171615310*1***
18101694*1***
19********NOT YET
Sheet1
 
It generates duplicates in the column but not in the row, it needs to be unique in column and row
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
please can you clarify your exact requirement then

you want 12 unique sets of 3 numbers chosen from 1-17. There are 680 possible combinations of numbers that meet this criteria
[17! / (14! * 3!)]

separately you want 8 unique sets of 4 numbers chosen from 1-17. There are 2380 possible combinations of numbers that meet this criteria
[17!/ (13! * 4!)]

Is it ok if a set of 4 is identical to any of the sets of 3, but with one additional value added, i.e. any set of 3 is a subset of any set of 4?

You might consider generating two complete sets of all possible unique combinations, then selecting your sets at random, again testing for uniqueness. The code to select which combination would be similar to my previous code (using e.g. 680 as a row number, instead of 17)

To generate all combinations, see my recent postings on a related subject here
 
Upvote 0
Ok, I need 20 groups in total, 12 of which are made up of 3 No's and 8 groups which are made up of 4 no's. This is spread over 4 days. So Day 1 is 3 x 3 and 2 x 4, so on for the next 3 days.

The numbers I substitute for Names. So I have 17 Names which I need to allocate into each of the table.

Each day the groups are random and that is easy to generate as you have shown. What I'm trying to achieve is that the groups on Day 2 are unique from Day 1, and on Day 3 they are unique from Days 1&2 and so on for day 4.

So I end up with 20 total groups all unique
 
Upvote 0
OK I got something which seems to work. It's a bit more like what you started with, but handles each column individually, then performs tests like I did previously

set up sheet:
A1:A17 formula "= RAND()"
B1:B17 values 1-17 in order
C1:C17 named range "personnelList"
C1 formula "=VLOOKUP(LARGE($A$1:$A$17,B1),$A$1:$B$17,2,FALSE)", copied down to C17
D1:G17 output section, blank at start of VBA run
H1 formula "=COUNTIF(D1:G1,C1)>0", copied down
H18 formula "=COUNTIF(H1:H17,TRUE)=0", named range "noDuplications"

code:
Code:
Sub writeGroups17()
Dim i As Integer
For i = 1 To 4
    Do
        Application.Calculate
        If Range("noDuplications").Value = True Then
            Range("personnelList").Copy
            Range("personnelList").Offset(0, i).PasteSpecial (xlPasteValues)
            Exit Do
        End If
    Loop
Next i
End Sub

I won't guarantee this gives results that meet your criteria on every occasion, but it seems to work the first few runs I've done. To guarantee it, you need to adjust the "noDuplications" formula to check there are no duplications within each individual group
 
Upvote 0
The closest I have come to getting this to a unique state is I suppose 98% which I can live with, ie only 2 duplicate matches, shown as such

Excel Workbook
ABCDEFGHI
2Col ACol BCol CCol D
311794116A
426118111B
5311161605C
64134906D
751712115E
86513113F
97817212G
10812911113H
119221408I
12101514717J
131191010012K
1412315117L
1513461711M
16141453010N
17151636114O
18161081314P
19177121519Q
20
21Day 1Day 2Day 3Day 4
22Group 1MLQP1
23GDBI1
24FBAA0
25Group 2PHPQ0
26CMJK1
27DCHM1
28Group 3JILG1
29IKQB1
30QGGO0
31Group 4NEOJ1
32BQNN0
33KFMC1
34HPDL1
35Group 5OOCF0
36EAFD1
37ANIH1
38LJKE1
Sheet1


Took me ages to work out as I struggled to automate this Matrix, WXYZ is Day 1,2,3,4

Excel Workbook
JKLMNOPQRSTUVWXYZAA
1Matrix of Who's Who
2ABCDEFGHIJKLMNOPQ
3AYWZWWZY
4BYXZWWXWZY
5CWYXYZYZXZW
6DXWZZZXYYYW
7EWZX/ZZWWXX
8FYZX/ZWZYYWXX
9GZWXXYWZY
10HWXZZZYWXWY
11IZYYXWX/YZW
12JZYWZZYW
13KWYYXWX/YZWZ
14LWXZXWYZZWY
15MXYWWXZYYZ
16NWZYWZWZYY
17OWZYWZWYY
18PZWWXXYZYX
19QYYXXYWWZYZX
Sheet1


I could get the basic Match right but where it duplicated threw me. Any suggestions?
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,632
Members
449,241
Latest member
NoniJ

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