How to nesting array value according to cell value

Viewed 31

I have array from stuff length. I want to put these array to specific box length. How many box do ı need. For Example ı have ; lenght array is (2,2,4,5,5,10,3,3,3,1) box lenght value is 10. So My result will be

"You need 4 boxes and put them like this 1(10) 2(5,5) 3(3,3,3,1) 4(2,2,4)"

Public Sub Nestarray()
Dim ws As Worksheet
Dim lr As Long
Dim i As Long
Dim lenght() As Variant
Dim lenghtgroup() As Variant

Set ws = ActiveSheet

'First array
lr = Cells(Rows.Count, "D").End(xlUp).Row
lenght = ws.Range("D2:D" & lr).Value

'Second array I give space between stuff
ReDim lenghtgroup(LBound(lenght, 1) To UBound(lenght, 1), 1 To 1)
For i = LBound(lenght, 1) To UBound(lenght, 1)
    If Int(lenght(i, 1)) = ws.Range("H3").Value Then
        lenghtgroup(i, 1) = Int(lenght(i, 1))
    Else
        lenghtgroup(i, 1) = Int(lenght(i, 1) + ws.Range("H4").Value)
    End If

Next i
End Sub
0 Answers
Related