VerIII:
Can usually find a solution in under 10 secs... if no exact solution can be found, process is under 1 min.
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> CountDown()
<SPAN style="color:#00007F">Dim</SPAN> TestArray()
<SPAN style="color:#00007F">Dim</SPAN> MaxArray(0 <SPAN style="color:#00007F">To</SPAN> 5, 0 <SPAN style="color:#00007F">To</SPAN> 5)
<SPAN style="color:#00007F">Dim</SPAN> ValArray(5)
<SPAN style="color:#00007F">Dim</SPAN> OpArray(3)
<SPAN style="color:#00007F">Dim</SPAN> r, c <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
Range("C9:O9").ClearContents
Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#007F00">'Get Values from A2:A7</SPAN>
<SPAN style="color:#00007F">For</SPAN> a = 0 <SPAN style="color:#00007F">To</SPAN> 5
ValArray(a) = Range("A" & a + 2)
<SPAN style="color:#00007F">Next</SPAN> a
<SPAN style="color:#007F00">'Initialize operators</SPAN>
OpArray(0) = "+"
OpArray(1) = "-"
OpArray(2) = "/"
OpArray(3) = "*"
<SPAN style="color:#007F00">'Initialize row and column values</SPAN>
r = 1
c = 3
StartTime = Timer
<SPAN style="color:#007F00">'Run possibilities for 3 value strings</SPAN>
<SPAN style="color:#00007F">For</SPAN> i = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> j = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> k = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> v = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> w = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#007F00">'Make sure all values are unique</SPAN>
<SPAN style="color:#00007F">If</SPAN> i = j <SPAN style="color:#00007F">Or</SPAN> i = k <SPAN style="color:#00007F">Or</SPAN> j = k <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> SkipValue3
<SPAN style="color:#007F00">'Test for goal & "closest"</SPAN>
<SPAN style="color:#00007F">If</SPAN> Evaluate(ValArray(i) & OpArray(v) & ValArray(j) & OpArray(w) & ValArray(k)) = Range("Goal").Value <SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#007F00">'Paste Values</SPAN>
Cells(9, 3) = ValArray(i)
Cells(9, 5) = ValArray(j)
Cells(9, 7) = ValArray(k)
Cells(9, 4) = OpArray(v)
Cells(9, 6) = OpArray(w)
<SPAN style="color:#007F00">'Paste formula</SPAN>
Cells(9, 15) = "=" & ValArray(i) & OpArray(v) & ValArray(j) & OpArray(w) & ValArray(k)
<SPAN style="color:#00007F">GoTo</SPAN> ByeBye
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> w
<SPAN style="color:#00007F">Next</SPAN> v
SkipValue3:
<SPAN style="color:#00007F">Next</SPAN> k
<SPAN style="color:#00007F">Next</SPAN> j
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#007F00">'Run possibilities for 4 value strings</SPAN>
<SPAN style="color:#00007F">For</SPAN> i = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> j = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> k = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> l = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> v = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> w = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> x = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#007F00">'Make sure values are unique</SPAN>
<SPAN style="color:#00007F">If</SPAN> i = j <SPAN style="color:#00007F">Or</SPAN> i = k <SPAN style="color:#00007F">Or</SPAN> i = l <SPAN style="color:#00007F">Or</SPAN> j = k <SPAN style="color:#00007F">Or</SPAN> j = l <SPAN style="color:#00007F">Or</SPAN> k = l <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> SkipValue4
<SPAN style="color:#007F00">'Test for goal</SPAN>
<SPAN style="color:#00007F">If</SPAN> Evaluate(ValArray(i) & OpArray(v) & ValArray(j) & OpArray(w) & ValArray(k) _
& OpArray(x) & ValArray(l)) = Range("Goal").Value <SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#007F00">'Paste Values</SPAN>
Cells(9, 3) = ValArray(i)
Cells(9, 5) = ValArray(j)
Cells(9, 7) = ValArray(k)
Cells(9, 9) = ValArray(l)
Cells(9, 4) = OpArray(v)
Cells(9, 6) = OpArray(w)
Cells(9, 8) = OpArray(x)
<SPAN style="color:#007F00">'Paste formula</SPAN>
Cells(9, 15) = "=" & ValArray(i) & OpArray(v) & ValArray(j) & OpArray(w) & ValArray(k) & OpArray(x) & ValArray(l)
<SPAN style="color:#00007F">GoTo</SPAN> ByeBye
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> x
<SPAN style="color:#00007F">Next</SPAN> w
<SPAN style="color:#00007F">Next</SPAN> v
SkipValue4:
<SPAN style="color:#00007F">Next</SPAN> l
<SPAN style="color:#00007F">Next</SPAN> k
<SPAN style="color:#00007F">Next</SPAN> j
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#007F00">'Run possibilities for 5 value strings</SPAN>
<SPAN style="color:#00007F">For</SPAN> i = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> j = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> k = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> l = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> m = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> v = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> w = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> x = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> y = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#007F00">'Make sure all values are unique</SPAN>
<SPAN style="color:#00007F">If</SPAN> i = j <SPAN style="color:#00007F">Or</SPAN> i = k <SPAN style="color:#00007F">Or</SPAN> i = l <SPAN style="color:#00007F">Or</SPAN> i = m <SPAN style="color:#00007F">Or</SPAN> j = k <SPAN style="color:#00007F">Or</SPAN> j = l _
<SPAN style="color:#00007F">Or</SPAN> j = m <SPAN style="color:#00007F">Or</SPAN> k = l <SPAN style="color:#00007F">Or</SPAN> k = m <SPAN style="color:#00007F">Or</SPAN> l = m <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> SkipValue5
<SPAN style="color:#007F00">'Test for goal</SPAN>
<SPAN style="color:#00007F">If</SPAN> Evaluate(ValArray(i) & OpArray(v) & ValArray(j) & OpArray(w) & ValArray(k) _
& OpArray(x) & ValArray(l) & OpArray
& ValArray(m)) = Range("Goal").Value <SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#007F00">'Paste Values</SPAN>
Cells(9, 3) = ValArray(i)
Cells(9, 5) = ValArray(j)
Cells(9, 7) = ValArray(k)
Cells(9, 9) = ValArray(l)
Cells(9, 11) = ValArray(m)
Cells(9, 4) = OpArray(v)
Cells(9, 6) = OpArray(w)
Cells(9, 8) = OpArray(x)
Cells(9, 10) = OpArray
<SPAN style="color:#007F00">'Paste formula</SPAN>
Cells(9, 15) = "=" & ValArray(i) & OpArray(v) & ValArray(j) & OpArray(w) & ValArray(k) _
& OpArray(x) & ValArray(l) & OpArray
& ValArray(m)
<SPAN style="color:#00007F">GoTo</SPAN> ByeBye
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> y
<SPAN style="color:#00007F">Next</SPAN> x
<SPAN style="color:#00007F">Next</SPAN> w
<SPAN style="color:#00007F">Next</SPAN> v
SkipValue5:
<SPAN style="color:#00007F">Next</SPAN> m
<SPAN style="color:#00007F">Next</SPAN> l
<SPAN style="color:#00007F">Next</SPAN> k
<SPAN style="color:#00007F">Next</SPAN> j
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#007F00">'Run possibilities for 6 value strings</SPAN>
<SPAN style="color:#00007F">For</SPAN> i = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> j = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> k = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> l = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> m = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> n = 0 <SPAN style="color:#00007F">To</SPAN> 5
<SPAN style="color:#00007F">For</SPAN> v = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> w = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> x = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> y = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#00007F">For</SPAN> z = 0 <SPAN style="color:#00007F">To</SPAN> 3
<SPAN style="color:#007F00">'Make sure all values are unique</SPAN>
<SPAN style="color:#00007F">If</SPAN> i = j <SPAN style="color:#00007F">Or</SPAN> i = k <SPAN style="color:#00007F">Or</SPAN> i = l <SPAN style="color:#00007F">Or</SPAN> i = m <SPAN style="color:#00007F">Or</SPAN> i = n <SPAN style="color:#00007F">Or</SPAN> j = k <SPAN style="color:#00007F">Or</SPAN> j = l <SPAN style="color:#00007F">Or</SPAN> j = m _
<SPAN style="color:#00007F">Or</SPAN> j = n <SPAN style="color:#00007F">Or</SPAN> k = l <SPAN style="color:#00007F">Or</SPAN> k = m <SPAN style="color:#00007F">Or</SPAN> k = n <SPAN style="color:#00007F">Or</SPAN> l = m <SPAN style="color:#00007F">Or</SPAN> l = n <SPAN style="color:#00007F">Or</SPAN> m = n <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> SkipValue6
<SPAN style="color:#007F00">'Test for goal</SPAN>
<SPAN style="color:#00007F">If</SPAN> Evaluate(ValArray(i) & OpArray(v) & ValArray(j) & OpArray(w) & ValArray(k) _
& OpArray(x) & ValArray(l) & OpArray
& ValArray(m) & OpArray(z) & ValArray
) = Range("Goal").Value <SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#007F00">'Paste Values</SPAN>
Cells(9, 3) = ValArray(i)
Cells(9, 5) = ValArray(j)
Cells(9, 7) = ValArray(k)
Cells(9, 9) = ValArray(l)
Cells(9, 11) = ValArray(m)
Cells(9, 13) = ValArray
Cells(9, 4) = OpArray(v)
Cells(9, 6) = OpArray(w)
Cells(9, 8) = OpArray(x)
Cells(9, 10) = OpArray
Cells(9, 12) = OpArray(z)
<SPAN style="color:#007F00">'Paste formula</SPAN>
Cells(9, 15) = "=" & ValArray(i) & OpArray(v) & ValArray(j) & OpArray(w) & ValArray(k) _
& OpArray(x) & ValArray(l) & OpArray
& ValArray(m) & OpArray(z) & ValArray
<SPAN style="color:#00007F">GoTo</SPAN> ByeBye
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> z
<SPAN style="color:#00007F">Next</SPAN> y
<SPAN style="color:#00007F">Next</SPAN> x
<SPAN style="color:#00007F">Next</SPAN> w
<SPAN style="color:#00007F">Next</SPAN> v
SkipValue6:
<SPAN style="color:#00007F">Next</SPAN> n
<SPAN style="color:#00007F">Next</SPAN> m
<SPAN style="color:#00007F">Next</SPAN> l
<SPAN style="color:#00007F">Next</SPAN> k
<SPAN style="color:#00007F">Next</SPAN> j
<SPAN style="color:#00007F">Next</SPAN> i
MsgBox "Sorry, that goal is not possible."
ByeBye:
EndTime = Timer
[N9] = "="
Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
MsgBox "Process took " & EndTime - StartTime & " seconds"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>