PC Review


Reply
Thread Tools Rate Thread

Combinations in a string of data

 
 
Eán
Guest
Posts: n/a
 
      26th Feb 2009
Is there a function / formula I can use to determine how many combinations a
string of data can return the same value?
For example:
10
15
20
5
There are 2 ways the above data can return the value 25.

Many thanks
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      26th Feb 2009
Requires a macro. How big is your table?

"Eán" wrote:

> Is there a function / formula I can use to determine how many combinations a
> string of data can return the same value?
> For example:
> 10
> 15
> 20
> 5
> There are 2 ways the above data can return the value 25.
>
> Many thanks

 
Reply With Quote
 
Eán
Guest
Posts: n/a
 
      26th Feb 2009
50 lines

"Joel" wrote:

> Requires a macro. How big is your table?
>
> "Eán" wrote:
>
> > Is there a function / formula I can use to determine how many combinations a
> > string of data can return the same value?
> > For example:
> > 10
> > 15
> > 20
> > 5
> > There are 2 ways the above data can return the value 25.
> >
> > Many thanks

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      26th Feb 2009
I had a similar macro that I needed to modify. I don't know how to input the
input numbers or how you want the results. Run this code and I will modify
as required

Public InStrings
Public combo
Public RowCount
Public ComboLen
Public NumbersMatch
Public Checktotal
Sub combinations()

Checktotal = 25
NumbersMatch = 0

InStrings = Array(10, 15, 20, 25)
Length = UBound(InStrings) + 1

Level = 1
RowCount = 1
For ComboLen = 1 To Length
ReDim combo(ComboLen)
Position = 0

Call recursive(Level, Position)
Next ComboLen
End Sub
Sub recursive(ByVal Level As Integer, ByVal Position As Integer)

Length = UBound(InStrings) + 1

For i = Position To (Length - 1)

'for combinations check if item already entered
found = False
For j = 0 To (Level - 2)
'combo is a count of the combinations,not the actual data
'123
'124
'125
'234
'235
'245
'345
'data is actually in InStrings
If combo(j) = i Then
found = True
Exit For
End If
Next j

If found = False Then
combo(Level - 1) = i
If Level = ComboLen Then
For j = 0 To (ComboLen - 1)
If j = 0 Then
ComboString = InStrings(combo(j))
Mytotal = Val(InStrings(combo(j)))
Else
ComboString = ComboString & "," & InStrings(combo(j))
Mytotal = Mytotal + Val(InStrings(combo(j)))
End If
Next j
Sheets("Sheet1").Range("A" & RowCount) = ComboString
Sheets("Sheet1").Range("B" & RowCount) = Mytotal
If Checktotal = Mytotal Then
NumbersMatch = NumbersMatch + 1
Sheets("Sheet1").Range("C" & RowCount) = NumbersMatch
End If
RowCount = RowCount + 1
Else
Call recursive(Level + 1, i)
End If
End If
Next i
End Sub




"Eán" wrote:

> 50 lines
>
> "Joel" wrote:
>
> > Requires a macro. How big is your table?
> >
> > "Eán" wrote:
> >
> > > Is there a function / formula I can use to determine how many combinations a
> > > string of data can return the same value?
> > > For example:
> > > 10
> > > 15
> > > 20
> > > 5
> > > There are 2 ways the above data can return the value 25.
> > >
> > > Many thanks

 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      27th Feb 2009
> 5,10,15,20....

Are you numbers in increments of 5?
5,10,15,20,25...250

Dana DeLouis



Eán wrote:
> 50 lines
>
> "Joel" wrote:
>
>> Requires a macro. How big is your table?
>>
>> "Eán" wrote:
>>
>>> Is there a function / formula I can use to determine how many combinations a
>>> string of data can return the same value?
>>> For example:
>>> 10
>>> 15
>>> 20
>>> 5
>>> There are 2 ways the above data can return the value 25.
>>>
>>> Many thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Isolating specific string combinations Demosthenes Microsoft Excel Misc 3 3rd Sep 2009 05:40 PM
Isolating string combinations Demosthenes Microsoft Excel Worksheet Functions 3 28th Aug 2009 06:06 PM
Generate data with all combinations Venkatesh V Microsoft Excel Programming 5 27th Nov 2008 11:59 AM
Help with a formula: Data Combinations Maureno Microsoft Excel Misc 3 22nd Oct 2008 02:45 PM
Using Keyboard combinations to insert data =?Utf-8?B?Qm9iIE11bGxlbg==?= Microsoft Access Form Coding 0 30th Jul 2004 02:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:22 PM.