I searched for a similar question but couldn't find one..
I want to generate 10 groups out of numbers ranging from 1-60 (including both), with each and every group containing random and non-repeating numbers. How can I do this in excel?
Answer
How to use it
- Open Excel & VBA editor (Alt+F11)
- Insert the code below under
Sheet1
- Go back to Excel and select your desired range to fill with random & non-repeating numbers
- Execute the macro (Alt+F8)
Sub randomNumbers()
Low = Application.InputBox("Enter first valid value", Type:=1)
High = Application.InputBox("Enter last valid value", Type:=1)
Selection.Clear
For Each cell In Selection.Cells
If WorksheetFunction.CountA(Selection) = (High - Low + 1) Then Exit For
Do
rndNumber = Int((High - Low + 1) * Rnd() + Low)
Loop Until Selection.Cells.Find(rndNumber, LookIn:=xlValues, lookat:=xlWhole) Is Nothing
cell.Value = rndNumber
Next
End Sub
I love those small and simple solutions so much
No comments:
Post a Comment