noveske
Board Regular
- Joined
- Apr 15, 2022
- Messages
- 120
- Office Version
- 365
- Platform
- Windows
- Mobile
- Web
Currently this code generates 16 numbers and places them in C4:C19.
How would I set it to every other?
So instead of every cell in the column, I just need it to generate in every other, C4, C6, C8, C10, C12, C14, C16, C18.
Tried setting that as range, but would halt at sort. Also tried offsetting. I think I was off.
Then I'm trying to make it every other match in pairs. So C5=C4, C7=C6, C9=C8, C11=C10, C13=C12, C15=C14, C17=C16, C19=C18.
Then sort.
Only way I can think of is to generate and sort on another sheet, then reference to that page. Then hide the page of values?
Currently:
Trying to get it to:
How would I set it to every other?
So instead of every cell in the column, I just need it to generate in every other, C4, C6, C8, C10, C12, C14, C16, C18.
Tried setting that as range, but would halt at sort. Also tried offsetting. I think I was off.
Then I'm trying to make it every other match in pairs. So C5=C4, C7=C6, C9=C8, C11=C10, C13=C12, C15=C14, C17=C16, C19=C18.
Then sort.
Only way I can think of is to generate and sort on another sheet, then reference to that page. Then hide the page of values?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r&, k&, lim1&, lim2&, lim3&, arr(1 To 16, 1 To 1)
Dim dic1 As Object: Set dic1 = CreateObject("Scripting.dictionary")
Dim dic2 As Object: Set dic2 = CreateObject("Scripting.dictionary")
If Intersect(Target, Union(Range("E2"), Range("A2"))) Is Nothing Then Exit Sub
If Target.Address(0, 0) = "A2" Then
Range("A4:A19").Value = Range("A2").Value
Else
If Target.Value = "R" Then
lim1 = 36: lim2 = 44: lim3 = 75
Else
lim1 = 32: lim2 = 33: lim3 = 64
End If
Randomize
Do
r = Int(Rnd() * lim1) + 1
If Not dic1.exists(r) Then
k = k + 1
dic1.Add r, ""
arr(k, 1) = r
End If
Loop Until k = 8
Do
r = Int(Rnd() * lim3) + 1
If Not dic2.exists(r) And r >= lim2 Then
k = k + 1
dic2.Add r, ""
arr(k, 1) = r
End If
Loop Until k = 16
With Range("C4:C19")
.Value = arr
.Sort Range("C3")
End With
End If
End Sub
Currently:
Trying to get it to: