This little macro will do it perfectly ... So far.
Need to just put the result required in a cell named ³ans² and then the
values required in a column. Just click on the first value and run ...
I¹m sure there is other ways around the problem, but it doesn¹t look like
anyone has given many ideas ...
Brad.)
Sub findsums()
Dim pos As Integer
Dim rng As Range
Dim cell As Object
Dim testvalue As Integer
Dim test As Integer
Dim triga As Integer
Dim trigb As Integer
Dim trigc As Integer
Dim trigd As Integer
Dim trige As Integer
Dim trigf As Integer
Dim trigg As Integer
Dim trigh As Integer
Dim trigi As Integer
Dim trigj As Integer
Dim trigk As Integer
Dim trigl As Integer
Dim trigm As Integer
Dim trign As Integer
Dim a As Integer, b As Integer, c As Integer, d As Integer, e As Integer, f
As Integer, g As Integer, h As Integer, i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim n As Integer
Dim result As String
Set rng = Selection
testvalue = Range("ans").Value
MsgBox testvalue & " is being tested"
pos = 1
For triga = 0 To 1
For trigb = 0 To 1
For trigc = 0 To 1
For trigd = 0 To 1
For trige = 0 To 1
For trigf = 0 To 1
For trigg = 0 To 1
For trigh = 0 To 1
For trigi = 0 To 1
For trigj = 0 To 1
For trigk = 0 To 1
For trigl = 0 To 1
For trigm = 0 To 1
For trign = 0 To 1
a = rng.Cells(1, 1).Value * triga
b = rng.Cells(2, 1).Value * trigb
c = rng.Cells(3, 1).Value * trigc
d = rng.Cells(4, 1).Value * trigd
e = rng.Cells(5, 1).Value * trige
f = rng.Cells(6, 1).Value * trigf
g = rng.Cells(7, 1).Value * trigg
h = rng.Cells(8, 1).Value * trigh
i = rng.Cells(9, 1).Value * trigi
j = rng.Cells(10, 1).Value * trigj
k = rng.Cells(11, 1).Value * trigk
l = rng.Cells(12, 1).Value * trigl
m = rng.Cells(13, 1).Value * trigm
n = rng.Cells(14, 1).Value * trign
'MsgBox a & b & c & d
test = a + b + c + d + e + f + g + h + i + j + k + l + m + n
If test = testvalue Then
result = a & " + " & b & " + " & c & " + " & d & " + " & e & " + " & f & " +
" & g & " + " & h & " + " & i & " + " & j & " + " & k & " + " & l & " + " &
m & " + " & n
Dim s As Integer
s = 1
j = 1
ŒThe following while will remove all the ³0¹s² from the expression ...
While j > 0
j = InStr(s, result, "0")
If (InStr(s, result, "10") + 1) <> j Or (InStr(s, result, "10")) = 0 Then
Select Case j
Case Len(result)
result = Mid(result, 1, (Len(result) - 3))
Case 1
result = Mid(result, j + 4, Len(result))
Case 0
'do nothing
Case Else
result = Mid(result, 1, j - 1) + Mid(result, j + 4, Len(result))
End Select
Else
s = j + 2
End If
Wend
If Len(result) <> 1 Then
rng.Cells(pos, 3).Value = result
pos = pos + 1
Else: End If
Else: End If
Next trign: Next trigm: Next trigl: Next trigk: Next trigj: Next trigi
Next trigh: Next trigg: Next trigf: Next trige
Next trigd: Next trigc: Next trigb: Next triga
End Sub