Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel should take a range of numbers and calculate different num..

from an old post:

one method using solver:
http://groups.google.com/groups?thre...gp13.phx .gbl

will find a single solution.

The below will find multiple solutions if they exist. As Harlan points out
in the above thread the problem can quickly escalate to be unsolvable, but
for the numbers you show, it is solvable.

http://groups.google.com/groups?thre....supernews.com

Put your numbers in Column B, starting in B1
Put the number to sum to in A1
Run TestBldBin

this will list all combinations in columns going to the right - obviously it
runs out of room at 256. If nothing is shown, there are no combinations
(for example 9999 with the sample 14 numbers).

Option Explicit
Sub bldbin(num As Long, bits As Long, arr() As Long)
Dim lNum As Long, i As Long, cnt As Long
lNum = num
' Dim sStr As String
' sStr = ""
cnt = 0
For i = bits - 1 To 0 Step -1
If lNum And 2 ^ i Then
cnt = cnt + 1
arr(i, 0) = 1
' sStr = sStr & "1"
Else
arr(i, 0) = 0
' sStr = sStr & "0"
End If
Next
' If cnt = 2 Then
' Debug.Print num, sStr
' End If
End Sub

Sub TestBldbin()
Dim i As Long
Dim bits As Long
Dim varr As Variant
Dim varr1() As Long
Dim rng As Range
Dim icol As Long
Dim tot As Long
Dim num As Long
icol = 0
Set rng = Range(Range("B1"), Range("B1").End(xlDown))
num = 2 ^ rng.Count - 1
bits = rng.Count
varr = rng.Value
ReDim varr1(0 To bits - 1, 0 To 0)
For i = 0 To num
bldbin i, bits, varr1
tot = Application.SumProduct(varr, varr1)
If tot = Range("A1") Then
icol = icol + 1
If icol = 255 Then
MsgBox "too many columns, i is " & i & " of " & num & _
" combinations checked"
Exit Sub
End If
rng.Offset(0, icol) = varr1
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"Jarom" wrote in message
...
Is Excel capable of taking a range of numbers, lets say 1000 and derrive

the
different number or cell combinations to make a specific number that you

are
looking for. It would be a type of Goal Seek but it would not change the
cell, only add different cells across the range to find the number you are
looking for.

This would help in auditing, reconciliations, and numerous other

accounting
functions.
Thanks



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
calculate percentage of numbers <= zero in a given range spowel4 Excel Worksheet Functions 3 July 23rd 08 05:08 PM
Calculate an Excel column that contains numbers and #Values Kevin Excel Discussion (Misc queries) 3 August 9th 06 04:35 PM
Excel Formula - to calculate highest number from a set of numbers Emily Excel Worksheet Functions 1 June 27th 06 06:49 AM
Can I calculate negative numbers to = zero in excel? HeyTriciaC Excel Discussion (Misc queries) 3 August 29th 05 09:53 PM
Excel 2000 - range.calculate error - 2147417848 Stephan Kostial Excel Programming 0 February 16th 04 08:28 AM


All times are GMT +1. The time now is 01:59 PM.

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"