Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default I need a formula that equals a given #

Does anyone know how to create a formula with 5 sets of numbers that
have to equal another number? For example, if
Set 1 = (1,2,3)
Set 2 = (4,5,6)
Set 3 = (7,8,9)
Set 4 = (10,11,12)
Set 5 = (13,14,15)

I would want the formula to pick one number from each set so that the
sum of these numbers would equal 40. Is there a way to write a formula
in Excel that would create all of the possible number combinations
(using the 5 sets) that equal a given number?

Thanks in advance for your help!

Spencer



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default I need a formula that equals a given #

Sorry, I missed a line out.
add
End If
before
Next fifth

Henry

"Henry" wrote in message
...
Spencer,

Here's one way

Assuming that Set 1 is in A1, B1 & C1 and Set 2 is in A2, B2 & C2 etc.,
etc.,
and your list of matches goes into D1 to H1 for the first match, D2 to H2
for the second match, etc., etc.

counter = 1
For first = 1 To 3
For second = 1 To 3
For third = 1 To 3
For fourth = 1 To 3
For fifth = 1 To 3
If Cells(1, first).Value + Cells(2, second).Value + Cells(3, third).Value

_
+ Cells(4, fourth).Value + Cells(5, fifth).Value = 40 Then
'Found a match
Cells(counter, 4).Value = Cells(1, first).Value
Cells(counter, 5).Value = Cells(2, second).Value
Cells(counter, 6).Value = Cells(3, third).Value
Cells(counter, 7).Value = Cells(4, fourth).Value
Cells(counter, 8).Value = Cells(5, fifth).Value
counter = counter + 1
Next fifth
Next fourth
Next third
Next second
Next first

Not very elegant or fast, but it'll do the job for you.

HTH
Henry


"Spencer G." wrote in message
...
Does anyone know how to create a formula with 5 sets of numbers that
have to equal another number? For example, if
Set 1 = (1,2,3)
Set 2 = (4,5,6)
Set 3 = (7,8,9)
Set 4 = (10,11,12)
Set 5 = (13,14,15)

I would want the formula to pick one number from each set so that the
sum of these numbers would equal 40. Is there a way to write a formula
in Excel that would create all of the possible number combinations
(using the 5 sets) that equal a given number?

Thanks in advance for your help!

Spencer



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default I need a formula that equals a given #

Sorry, I missed a line out.
add
End If
before
Next fifth

Henry

"Henry" wrote in message
...
Spencer,

Here's one way

Assuming that Set 1 is in A1, B1 & C1 and Set 2 is in A2, B2 & C2 etc.,
etc.,
and your list of matches goes into D1 to H1 for the first match, D2 to H2
for the second match, etc., etc.

counter = 1
For first = 1 To 3
For second = 1 To 3
For third = 1 To 3
For fourth = 1 To 3
For fifth = 1 To 3
If Cells(1, first).Value + Cells(2, second).Value + Cells(3, third).Value

_
+ Cells(4, fourth).Value + Cells(5, fifth).Value = 40 Then
'Found a match
Cells(counter, 4).Value = Cells(1, first).Value
Cells(counter, 5).Value = Cells(2, second).Value
Cells(counter, 6).Value = Cells(3, third).Value
Cells(counter, 7).Value = Cells(4, fourth).Value
Cells(counter, 8).Value = Cells(5, fifth).Value
counter = counter + 1
Next fifth
Next fourth
Next third
Next second
Next first

Not very elegant or fast, but it'll do the job for you.

HTH
Henry


"Spencer G." wrote in message
...
Does anyone know how to create a formula with 5 sets of numbers that
have to equal another number? For example, if
Set 1 = (1,2,3)
Set 2 = (4,5,6)
Set 3 = (7,8,9)
Set 4 = (10,11,12)
Set 5 = (13,14,15)

I would want the formula to pick one number from each set so that the
sum of these numbers would equal 40. Is there a way to write a formula
in Excel that would create all of the possible number combinations
(using the 5 sets) that equal a given number?

Thanks in advance for your help!

Spencer



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default I need a formula that equals a given #

Sorry, I missed a line out.
add
End If
before
Next fifth

Henry

"Henry" wrote in message
...
Spencer,

Here's one way

Assuming that Set 1 is in A1, B1 & C1 and Set 2 is in A2, B2 & C2 etc.,
etc.,
and your list of matches goes into D1 to H1 for the first match, D2 to H2
for the second match, etc., etc.

counter = 1
For first = 1 To 3
For second = 1 To 3
For third = 1 To 3
For fourth = 1 To 3
For fifth = 1 To 3
If Cells(1, first).Value + Cells(2, second).Value + Cells(3, third).Value

_
+ Cells(4, fourth).Value + Cells(5, fifth).Value = 40 Then
'Found a match
Cells(counter, 4).Value = Cells(1, first).Value
Cells(counter, 5).Value = Cells(2, second).Value
Cells(counter, 6).Value = Cells(3, third).Value
Cells(counter, 7).Value = Cells(4, fourth).Value
Cells(counter, 8).Value = Cells(5, fifth).Value
counter = counter + 1
Next fifth
Next fourth
Next third
Next second
Next first

Not very elegant or fast, but it'll do the job for you.

HTH
Henry


"Spencer G." wrote in message
...
Does anyone know how to create a formula with 5 sets of numbers that
have to equal another number? For example, if
Set 1 = (1,2,3)
Set 2 = (4,5,6)
Set 3 = (7,8,9)
Set 4 = (10,11,12)
Set 5 = (13,14,15)

I would want the formula to pick one number from each set so that the
sum of these numbers would equal 40. Is there a way to write a formula
in Excel that would create all of the possible number combinations
(using the 5 sets) that equal a given number?

Thanks in advance for your help!

Spencer



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default I need a formula that equals a given #

Here is just a slightly different technique to your excellent idea...

Sub test()

Dim Set1, Set2, Set3, Set4, Set5
Dim result As Long
Dim i As Long, j As Long, k As Long, l As Long, m As Long

Set1 = Array(, 1, 2, 3)
Set2 = Array(, 4, 5, 6)
Set3 = Array(, 7, 8, 9)
Set4 = Array(, 10, 11, 12)
Set5 = Array(, 13, 14, 15)

For i = 1 To 3
For j = 1 To 3
For k = 1 To 3
For l = 1 To 3
For m = 1 To 3
result = Set1(i) + Set2(j) + Set3(k) + Set4(l) + Set5(m)
If result = 40 Then Debug.Print Set1(i); Set2(j);
Set3(k); Set4(l); Set5(m); result
Next m
Next l
Next k
Next j
Next i

End Sub



--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Doug Glancy" wrote in message
...
Spencer,

I look forward to seeing more concise answers (I don't use arrays much),

but
this seems to work:

Sub test()

Dim Set1(1 To 3), Set2(1 To 3), Set3(1 To 3), Set4(1 To 3), Set5(1 To 3),
result As Long
Dim i, j, k, l, m As Integer

Set1(1) = (1)
Set1(2) = (2)
Set1(3) = (3)
Set2(1) = (4)
Set2(2) = (5)
Set2(3) = (6)
Set3(1) = (7)
Set3(2) = (8)
Set3(3) = (9)
Set4(1) = (10)
Set4(2) = (11)
Set4(3) = (12)
Set5(1) = (13)
Set5(2) = (14)
Set5(3) = (15)

For i = 1 To 3
For j = 1 To 3
For k = 1 To 3
For l = 1 To 3
For m = 1 To 3
result = Set1(i) + Set2(j) + Set3(k) + Set4(l) +

Set5(m)
If result = 40 Then Debug.Print Set1(i); Set2(j);
Set3(k); Set4(l); Set5(m); result
Next m
Next l
Next k
Next j
Next i

End Sub


"Spencer G." wrote in message
...
Does anyone know how to create a formula with 5 sets of numbers that
have to equal another number? For example, if
Set 1 = (1,2,3)
Set 2 = (4,5,6)
Set 3 = (7,8,9)
Set 4 = (10,11,12)
Set 5 = (13,14,15)

I would want the formula to pick one number from each set so that the
sum of these numbers would equal 40. Is there a way to write a formula
in Excel that would create all of the possible number combinations
(using the 5 sets) that equal a given number?

Thanks in advance for your help!

Spencer



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Equals formula DataGuy Excel Discussion (Misc queries) 2 May 28th 09 10:09 PM
If a cell equals _, at the next row that equals _, return value fr CathyH Excel Worksheet Functions 10 May 2nd 07 07:53 PM
if a:a (range) equals january and c:c equals gas then add g:g ($) BCOz Excel Worksheet Functions 4 December 29th 05 07:40 PM
sum formula equals zero shathun Excel Worksheet Functions 2 July 26th 05 05:55 PM
custom filter does not work when selecting 'equals' X AND 'equals' plindman Excel Discussion (Misc queries) 1 June 1st 05 11:29 PM


All times are GMT +1. The time now is 04:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"