ststern45
Well-known Member
- Joined
- Sep 17, 2005
- Messages
- 974
- Office Version
- 365
- 2010
- Platform
- Windows
Below is the code for calculating "how far back" or in other words how many previous drawings did it take for all 3 digits to appear from each of the 3 positions.
The code below is for a 3 digits that range from 0 through 9. Digits can repeat from the original set of 3 numbers analyzed.
3 digit/position example:
Cell range S20 through U20
S20 = 4
T20 = 2
U20 = 1
Starting from cell range S20 through U19 the calculations look at the following digits:
The result would be 7
4 2 1 <Cell S20, T20, U20 For all 3 digits it required 7 previous rows for all 3 digits to appear
1 6 3 <1
0 2 3 <2
6 7 8 <3
7 3 5 <4
1 2 1 <5
3 3 5 <6
4 4 7 <7
6 0 2
7 6 0
4 1 0
7 7 5
7 4 1
4 4 0
0 8 5
7 3 6
1 0 5
5 2 6
9 8 0
8 9 6
1 2 7
0 9 1
9 3 7
1 5 2
9 9 0
8 6 6
1 0 8
8 4 3
1 4 9
3 2 3
3 5 4
0 4 1
7 8 3
9 6 1
6 1 1
5 3 9
5 2 6
4 2 1
6 6 1
6 5 8
9 2 3
3 5 7
0 8 5
5 3 8
0 4 3
1 9 9
2 6 6
4 0 1
5 0 2
0 4 4
4 9 7
7 2 5
9 5 9
1 4 5
4 4 3
8 6 6
7 8 1
7 2 6
4 8 9
9 4 6
5 4 1
8 5 1
8 0 1
0 4 1
2 0 6
0 5 8
5 2 0
3 5 1
1 0 2
6 9 7
8 1 5
6 5 4
0 1 9
5 9 1
5 4 4
6 0 8
7 2 3
0 1 5
3 5 0
9 6 2
2 2 7
0 3 9
6 3 7
9 7 0
4 6 4
9 7 9
6 5 0
9 5 1
6 9 9
6 2 4
8 6 0
7 1 3
6 8 7
2 9 1
8 4 0
4 0 5
4 7 4
4 1 5
0 6 9
7 1 1
I need help with the code in order to analyze 4 digits instead of 3 digits.
Thank you in advance!!
The code below is for a 3 digits that range from 0 through 9. Digits can repeat from the original set of 3 numbers analyzed.
3 digit/position example:
Cell range S20 through U20
S20 = 4
T20 = 2
U20 = 1
Starting from cell range S20 through U19 the calculations look at the following digits:
The result would be 7
4 2 1 <Cell S20, T20, U20 For all 3 digits it required 7 previous rows for all 3 digits to appear
1 6 3 <1
0 2 3 <2
6 7 8 <3
7 3 5 <4
1 2 1 <5
3 3 5 <6
4 4 7 <7
6 0 2
7 6 0
4 1 0
7 7 5
7 4 1
4 4 0
0 8 5
7 3 6
1 0 5
5 2 6
9 8 0
8 9 6
1 2 7
0 9 1
9 3 7
1 5 2
9 9 0
8 6 6
1 0 8
8 4 3
1 4 9
3 2 3
3 5 4
0 4 1
7 8 3
9 6 1
6 1 1
5 3 9
5 2 6
4 2 1
6 6 1
6 5 8
9 2 3
3 5 7
0 8 5
5 3 8
0 4 3
1 9 9
2 6 6
4 0 1
5 0 2
0 4 4
4 9 7
7 2 5
9 5 9
1 4 5
4 4 3
8 6 6
7 8 1
7 2 6
4 8 9
9 4 6
5 4 1
8 5 1
8 0 1
0 4 1
2 0 6
0 5 8
5 2 0
3 5 1
1 0 2
6 9 7
8 1 5
6 5 4
0 1 9
5 9 1
5 4 4
6 0 8
7 2 3
0 1 5
3 5 0
9 6 2
2 2 7
0 3 9
6 3 7
9 7 0
4 6 4
9 7 9
6 5 0
9 5 1
6 9 9
6 2 4
8 6 0
7 1 3
6 8 7
2 9 1
8 4 0
4 0 5
4 7 4
4 1 5
0 6 9
7 1 1
VBA Code:
Public Function HowFar(ByVal MyRange As Range, ByVal MyCount As Long)
Dim MyData As Variant, i As Long, j As Long, k As Long
MyData = MyRange.Value
For i = 2 To UBound(MyData)
For j = 1 To 3
For k = 1 To 3
If MyData(i, j) = MyData(1, k) Then
MyCount = MyCount - 1
MyData(1, k) = "x"
If MyCount = 0 Then
HowFar = i - 1
Exit Function
End If
Exit For
End If
Next k
Next j
Next i
HowFar = ""
End Function
I need help with the code in order to analyze 4 digits instead of 3 digits.
Thank you in advance!!
Last edited by a moderator: