Home > Software Tutorial > Office Software > How to generate random numbers for roommates using Excel

How to generate random numbers for roommates using Excel

WBOY
Release: 2024-01-09 11:14:38
forward
668 people have browsed it

How to randomly generate numbers with roommate excel 145 without repeating I am not very good at excel and need to learn

Sub CreateRND()

Dim arr() As Integer 'Define array

ReDim arr(range("d3").Value) 'Change the array size

Dim min As Integer 'Define the minimum value of a random number

Dim max As Integer 'Define the maximum value of random numbers

Dim flag As Boolean 'Define flag variable to determine whether there are duplicate values

max = range("d2").Value 'Assign the value of cell d2 to the maximum value

min = range("d1").Value 'Assign the value of cell d1 to the minimum value

If (max - min 1

Exit Sub

End If

Randomize (Now()) 'Use the current time to generate a random number seed

For i = 0 To range("d3").Value 'Loop to generate random numbers

Do

arr(i) = Rnd() * (max - min) min 'Generate random numbers

flag = False

For j = 0 To (i - 1) 'Loop to determine whether the current random number is the same as the previously generated random number, and if it is the same, regenerate it

If (arr(i) = arr(j)) Then

flag = True

End If

Next

Loop While flag

Next

Columns("A:A").ClearContents

range("a1").Resize(range("d3").Value) = Application.Transpose(arr) 'Output result

End Sub

How to make excel generate random numbers within a range

1. First calculate the difference in this range. It is assumed here that the range value is a random number within 50~100

How to generate random numbers for roommates using Excel

2. Open the spreadsheet and enter the following formula in the cell where you want to generate random numbers: =rand()*(100-50) 50. Press the confirm button to generate a random number within the specified range!

How to generate random numbers for roommates using Excel

3. If you need to generate multiple random numbers, just drag the small triangle in the bottom corner of the cell!

How to generate random numbers for roommates using Excel

Microsoft Excel is one of the components of Microsoft Office software. It is a spreadsheet software written and run by Microsoft for computers with Windows and Apple Macintosh operating systems. The earliest version was developed in 1985. .

Microsoft Excel can perform various data processing, statistical analysis and auxiliary decision-making operations, etc. It has the functions of opening or closing table header rows, calculated columns using a single formula to adjust each row, data sorting and filtering, custom formulas and text input, etc. Function. At present, Microsoft Excel is widely used in many fields such as management, statistics and finance, and finance.

The above is the detailed content of How to generate random numbers for roommates using Excel. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template