Sub MinCombo()
Dim i1, i2, i3, i4, i5, i6, i7, j, k, x, y, z, tt As Long
Dim arr()
If (Range("B2") > 0) Then i1 = Application.WorksheetFunction.RoundDown(Range("A2") / Range("B2"), 0)
If (Range("C2") > 0) Then i2 = Application.WorksheetFunction.RoundDown(Range("A2") / Range("C2"), 0)
If (Range("D2") > 0) Then i3 = Application.WorksheetFunction.RoundDown(Range("A2") / Range("D2"), 0)
If (Range("E2") > 0) Then i4 = Application.WorksheetFunction.RoundDown(Range("A2") / Range("E2"), 0)
If (Range("F2") > 0) Then i5 = Application.WorksheetFunction.RoundDown(Range("A2") / Range("F2"), 0)
If (Range("G2") > 0) Then i6 = Application.WorksheetFunction.RoundDown(Range("A2") / Range("G2"), 0)
If (Range("H2") > 0) Then i7 = Application.WorksheetFunction.RoundDown(Range("A2") / Range("H2"), 0)
tt = (i1 + 1) * (i2 + 1) * (i3 + 1) * (i4 + 1) * (i5 + 1) * (i6 + 1) * (i7 + 1)
response = MsgBox("No. of combinations are => " & tt, vbOK)
If response = vbCancel Then
MsgBox ("Macro Ending")
Exit Sub
End If
Range("A3:Z65536").Select
Selection.ClearContents
Range("B2").Select
ReDim arr(1 To tt, 1 To 16)
'##################### I WANT VBA CODES TO INPUT THE BELOW VALUES IN SCRIPTING.DIRECTORY #####################
For x1 = 0 To i1
For x2 = 0 To i2
For x3 = 0 To i3
For x4 = 0 To i4
For x5 = 0 To i5
For x6 = 0 To i6
For x7 = 0 To i7
i = i + 1
arr(i, 1) = x1
arr(i, 2) = x2
arr(i, 3) = x3
arr(i, 4) = x4
arr(i, 5) = x5
arr(i, 6) = x6
arr(i, 7) = x7
arr(i, 8) = Cells(2, "a") - Cells(2, "b") * x1 - Cells(2, "c") * x2 - Cells(2, "d") * x3 - Cells(2, "e") * x4 - Cells(2, "f") * x5 - Cells(2, "g") * x6 - Cells(2, "h") * x7
arr(i, 9) = x1 * Cells(2, "b") * Cells(1, "j") / Cells(2, "a")
arr(i, 10) = x2 * Cells(2, "c") * Cells(1, "j") / Cells(2, "a")
arr(i, 11) = x3 * Cells(2, "d") * Cells(1, "j") / Cells(2, "a")
arr(i, 12) = x4 * Cells(2, "e") * Cells(1, "j") / Cells(2, "a")
arr(i, 13) = x5 * Cells(2, "f") * Cells(1, "j") / Cells(2, "a")
arr(i, 14) = x6 * Cells(2, "g") * Cells(1, "j") / Cells(2, "a")
arr(i, 15) = x7 * Cells(2, "h") * Cells(1, "j") / Cells(2, "a")
arr(i, 16) = WorksheetFunction.Sum(arr(i, 9), arr(i, 10), arr(i, 11), arr(i, 12), arr(i, 13), arr(i, 14), arr(i, 15))
Next
Next
Next
Next
Next
Next
Next
Range("b3").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End Sub
Bookmarks