montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 984
- Office Version
- 2010
- Platform
- Windows
Hello every one,
I had been working in this little problem, and now I got error messages ►next without for◄ I count my for and next and everything are even, so I don't get it, I need some hand here. this code is about input some numbers on column A generate non repiten combination on C:H IF column H - column C in in the range indicated on A25 minimun and A26 maximun.
I still don't see the error.
please some advise.
let me explain with a little example. if on A25 value = 30 [min] and A26 45[max] then the different between the column H - column C if they are in this range THEN thats the perfect output.
like this combination
thats the only combinations I want to generate.
I had been working in this little problem, and now I got error messages ►next without for◄ I count my for and next and everything are even, so I don't get it, I need some hand here. this code is about input some numbers on column A generate non repiten combination on C:H IF column H - column C in in the range indicated on A25 minimun and A26 maximun.
HTML:
Option Explicit
Sub combinations()
Dim rRng As Range, p As Integer
Dim vElements, lRow As Variant, vresult As Variant
Set rRng = Range("A1", Range("A1").End(xlDown))
p = 6
vElements = Application.Index(Application.Transpose(rRng), 1, 0)
ReDim vresult(1 To p)
Call CombinationsNP(vElements, p, vresult, 1, 1)
End Sub
Sub CombinationsNP(vElements As Variant, p As Integer, vresult As Variant, iElement As Integer, ilndex As Integer)
Dim i As Integer
For i = iElement To UBound(vElements)
vresult(ilndex) = vElements(i)
Dim x As Long
Dim y As Long
For x = 1 To Cells(Rows.Count, "A").End(xlUp).Row
For y = 1 To 6
Next
Next
Cells(x, "I").Value = Cells(x, "H").Value - Cells(x, "C").Value
If Cells(x, "I").Value > Range("A25").Value And Cells(x, "I").Value < Range("A26") Then
Call CombinationsNP(vElements, p, vresult, i + 1, ilndex + 1)
If ilndex = p Then
If vresult(1) >= 1 And vresult(2) >= 3 And vresult(3) >= 5 And vresult(4) >= 9 Then
Cells(Application.Rows.Count, 3).End(xlUp).Offset(1, 0).Resize(, p) = vresult
End If
Else
Call CombinationsNP(vElements, p, vresult, i + 1, ilndex + 1)
End If
Next i
End Sub
please some advise.
let me explain with a little example. if on A25 value = 30 [min] and A26 45[max] then the different between the column H - column C if they are in this range THEN thats the perfect output.
like this combination
HTML:
7 8 23 35 49 51 [51-7=44]
10 18 28 41 44 51 [51-10=41 etc]
7 20 25 26 31 42
4 20 36 41 44 46