generate numbers without reversing the dozen on the same line

marreco

Well-known Member
Joined
Jan 1, 2011
Messages
609
Office Version
  1. 2010
Platform
  1. Windows
Hi.
I need to create random numbers with 10 columns and 10 rows.


But for each line can not be the number opposite each decade.

<colgroup><col span="9"><col><col span="9"></colgroup><tbody></tbody>
79224870049809413256
5917426756794474621
85667090898384508136
8350363575520395177
23673929128668188773
9035426721769134436
10113798841963542259
652635568619767569
33283859877463604190
9450012959833478791

<colgroup><col span="10"></colgroup><tbody>
</tbody>
see the first line was generated as the number 79, then this same line, can not generate the number 97.


number 22 in this case is OK.


The first line was generated the number 84, then this is not the same line, you can generate the number 48.


The first line was generated the number 07, then this is not the same line, you can generate the number 70.


and so
97228407409890142365

<tbody>
</tbody>
 
Hi.

for each row, I have 10 numbers with 2 digits.
this same line can not have the opposite digit.
eg
01 .... 70 ... 10 in this same line there can be, the number 10 and 07
or
10 ... 07 ... 01 in the same row can not be, the number 01 and 70
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi.

for each row, I have 10 numbers with 2 digits.
this same line can not have the opposite digit.
eg
01 .... 70 ... 10 in this same line there can be, the number 10 and 07
or
10 ... 07 ... 01 in the same row can not be, the number 01 and 70

You didn't answer Ricks questions..

Some questions...

1. Are all the numbers on the same row supposed to be unique (that is, no repeats anywhere among the values on the same row)?

2. If the numbers are not unique, can the first number be repeated?

3. I don't understand your comment about 22... are you saying 22 can repeat?

This version of my code allows duplicates but not reversed numbers, but I'm sure Rick can provide more effecient code.

Code:
Sub TEST()

Dim IsUnique As Boolean
Dim iNum As Integer
Dim r As Long
Dim c As Long

For r = 1 To 10

    ReDim Arr(0)
    
    'First Number
    iNum = WorksheetFunction.RandBetween(1, 99)
    Range("A1").Cells(r, 1).Value = iNum
        Arr(0) = fRNum(iNum)
        
    'Remaining numbers
    For i = 2 To 10
        IsUnique = False
        Do While IsUnique = False
            iNum = WorksheetFunction.RandBetween(1, 99)
                For x = 0 To UBound(Arr)
                    If iNum = Arr(x) Then
                        IsUnique = False
                        Exit For
                        Else
                        IsUnique = True
                    End If
                Next x
        Loop
                 
    ReDim Preserve Arr(UBound(Arr) + 1)
    Arr(UBound(Arr)) = fRNum(iNum)
    Range("A1").Cells(r, i).Value = iNum

    Next i

Next r

End Sub

Function fRNum(iNum As Integer) As Integer

If iNum < 10 Then
    fRNum = iNum * 10
    Else
    fRNum = (Right(iNum, 1) & Left(iNum, 1))
End If

End Function
 
Upvote 0

Forum statistics

Threads
1,221,788
Messages
6,161,963
Members
451,734
Latest member
Adapt375

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