Hi guys,
Wanting to be able to enter Class (ABC) and Number of rows needed and to randomly find, cut and paste the row from A-D into K-N according to class and number of lines required to be cut and pasted.
Any help would be appreciated!
Hi guys,
Wanting to be able to enter Class (ABC) and Number of rows needed and to randomly find, cut and paste the row from A-D into K-N according to class and number of lines required to be cut and pasted.
Any help would be appreciated!
Try
PHP Code:
Option Explicit
Sub randClass()
Dim lr&, i&, j&, k&, c&, t&, clas, r, cri(), res(1 To 1000, 1 To 4)
Dim dic As Object, cell As Range, key
Set dic = CreateObject("Scripting.dictionary")
lr = Cells(Rows.Count, "A").End(xlUp).Row
clas = Range("A2:D" & lr).Value
Randomize
For Each cell In Range("G2:I2")
ReDim cri(1 To UBound(clas), 1 To 4)
k = 0: c = 0
For i = 1 To UBound(clas)
If clas(i, 1) = cell.Value Then
k = k + 1
For j = 1 To 4
cri(k, j) = clas(i, j)
Next
End If
Next
If k > 0 Then
Do
r = Int(Rnd * k) + 1
If Not dic.exists(r) Then
dic.Add r, ""
c = c + 1: t = t + 1
For j = 1 To 4
res(t, j) = cri(r, j)
Next
Debug.Print r, c
If c = cell.Offset(1, 0).Value Then Exit Do
End If
Loop
End If
dic.RemoveAll
Next
Range("K2:N10000").ClearContents
If t > 0 Then Range("K2").Resize(t, 4).Value = res
End Sub
Quang PT
Another option.
Please Login or Register to view this content.
Last edited by kvsrinivasamurthy; 03-21-2024 at 07:31 AM.
Pl note
Array formula should be confirmed with Ctrl+Shift+Enter keys together.
If answere is satisfactory press * to add reputation.
Thanks so much guys, these are really good but I realize now that I need to cycle through and not repeat the selected SKU's
So same as before but without repeating the same SKU's so A Class and B Class will be repeating while still working through C.
Actually, I still don't understand what your new request is. Can you mock up the result area manually and upload the file again?
Ref Post#3.
There are no repetition. Pl verify once.
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks