Darshan Shah
New Member
- Joined
- Jul 4, 2020
- Messages
- 11
- Office Version
- 365
- Platform
- Windows
Hello,
I stuck in a middle of an output. Attaching herewith the code which i've used in my sheet. Existing output & require output is attached as image.
Below is a code.. Need some correction..
I stuck in a middle of an output. Attaching herewith the code which i've used in my sheet. Existing output & require output is attached as image.
Below is a code.. Need some correction..
VBA Code:
Option Explicit
Dim inparr() As Double, outarr() As String
Sub test()
Dim arr, i As Long
arr = Range(Cells(6, "A"), Cells(Rows.Count, "A").End(xlUp)).Value
ReDim inparr(1 To UBound(arr))
For i = 1 To UBound(arr)
inparr(i) = arr(i, 1)
Next i
ReDim outarr(1 To 1)
check_next_one "", 0, 0
If Range("E6") <> "" Then Range("E6").CurrentRegion.Clear
With Range("E6").Resize(UBound(outarr) - 1, 1)
.Value = Application.Transpose(outarr)
.TextToColumns Destination:=Range("E6"), DataType:=xlDelimited, Comma:=True
End With
End Sub
Sub check_next_one(ByVal currentset As String, ByVal currentsum As Double, ByVal currentposition As Long)
Dim i As Long
If currentsum <= Range("G1") Then 'else do nothing
If currentsum >= Range("G2") Then 'it's one of solutions
i = UBound(outarr)
ReDim Preserve outarr(1 To i + 1)
outarr(i) = currentset
End If
For i = currentposition + 1 To UBound(inparr)
check_next_one currentset & inparr(i) & ",", currentsum + inparr(i), i
Next i
End If
End Sub