Hi there,
Apologies if a similar query has already been raised and answered before - I tried searching but couldn't find a solution.
I have code that looks like this:
I am looking to expand this for 5, 6, 7, ..... basically any level of nestings, thereby saving me from a lot of copy-pastings. Any help would be most appreciated.
Apologies if a similar query has already been raised and answered before - I tried searching but couldn't find a solution.
I have code that looks like this:
Code:
'for 1 event(s) (need to generalize)
For i = 0 To LossSet - 1
Cells(RowCount, "C").Value = LossArray(i)
RowCount = RowCount + 1
Next
'for 2 event(s) (need to generalize)
For i = 0 To LossSet - 1
For j = 0 To LossSet - 1
Cells(RowCount, "C").Value = LossArray(i)
Cells(RowCount, "D").Value = LossArray(j)
RowCount = RowCount + 1
Next
Next
'for 3 event(s) (need to generalize)
For i = 0 To LossSet - 1
For j = 0 To LossSet - 1
For k = 0 To LossSet - 1
Cells(RowCount, "C").Value = LossArray(i)
Cells(RowCount, "D").Value = LossArray(j)
Cells(RowCount, "E").Value = LossArray(k)
RowCount = RowCount + 1
Next
Next
Next
'for 4 event(s) (need to generalize)
For i = 0 To LossSet - 1
For j = 0 To LossSet - 1
For k = 0 To LossSet - 1
For l = 0 To LossSet - 1
Cells(RowCount, "C").Value = LossArray(i)
Cells(RowCount, "D").Value = LossArray(j)
Cells(RowCount, "E").Value = LossArray(k)
Cells(RowCount, "F").Value = LossArray(l)
RowCount = RowCount + 1
Next
Next
Next
Next
I am looking to expand this for 5, 6, 7, ..... basically any level of nestings, thereby saving me from a lot of copy-pastings. Any help would be most appreciated.