Hi Everyone,
I'm new to this forum, but do have some VBA experience. However, I'm struggling to figure out how to get this code to give random values between 1 and 57. There are a total of 31 rows, and 53 columns (one column for each week of the year). What I'm looking for is some help to tweak this code where there are no duplicates within the column, but it's okay if there are duplicates in a row.
PLEASE HELP!
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim cell As Range
Dim Schedule As Range
Set Schedule = Range("B2:BB31")
If Target.Address = "$A$1" Then
For Each cell In Schedule
cell.Formula = WorksheetFunction.RandBetween(1, 57)
Next cell
For Each cell In Schedule
cell.Activate
If Application.WorksheetFunction.CountIf(Schedule, ActiveCell) > 1 Then
Do
ActiveCell.Formula = WorksheetFunction.RandBetween(1, 57)
Loop Until Application.WorksheetFunction.CountIf(Schedule, ActiveCell)
End If
Next cell
End If
End Sub
Bookmarks