Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
saustin
 
Posts: n/a
Default Searching a range of numbers for a specified total

I know that Excel has a way to search a range of numbers and try all
possible combinations in that range to see if any of the numbers in the
range equal a specified total. For example (a very simple example),
column A, with the numbers 102, 209, 315, 483 and 562. How do we get
Excel to search column A for the combination of cells that would equal
524?

I also know this requires solver, but am unsure of how to manipulate
solver to perform this task. Any tips would be greatly appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
John Michl
 
Posts: n/a
Default Searching a range of numbers for a specified total

Search Google Groups for the following thread:

function to find which cells add up to a given total?

That should get you started.

- John Michl

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
vezerid
 
Posts: n/a
Default Searching a range of numbers for a specified total

The suggested thread posted by John shows an excellent setup for the
Solver. However, this problem is a variant of the k-values problem (If
I remember the term correctly from my algorithms class), which is
NP-complete and too much for poor Solver if you have too many rows. I
tried it with 15 cells and the Solver found a solution quickly. I tried
it with 30 and it could not.

A very simplistic randomized optimization algorithm will try various
combinations until you hit the correct one. There is no guarantee how
long it will take. For N numbers we have a total of 2^N combinations.
However, it will find something. Then again, it might be better to try
exhaustive search, but for the moment this is the VBA code I am
suggesting:

Sub FindNumbers()
Do
Application.Calculation = xlCalculationManual
For i = 1 To 30
Cells(i, 2) = Int(Rnd() * 2)
Next i
Application.Calculation = xlCalculationAutomatic
Loop Until Range("D1") = 1124

End Sub

This macro supposes the same setup as in the thread, for numbers in
A1:A30 and 0/1's in B1:B30. The 1124 is the target sum.

HTH
Kostis Vezerides

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
Counting Unique Part Numbers In A Range BigH Excel Worksheet Functions 2 December 9th 05 08:09 PM
Adding numbers in one cell and showing total in seperate cell Deernad Construction Excel Discussion (Misc queries) 12 November 29th 05 08:32 PM
Adding numbers to a running total Elizabeth Free Excel Worksheet Functions 1 August 26th 05 11:27 PM
Match function...random search? Les Excel Worksheet Functions 10 July 28th 05 11:54 AM
How to total items if they fall between a date range cel Excel Discussion (Misc queries) 1 May 17th 05 07:30 PM


All times are GMT +1. The time now is 10:37 AM.

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

About Us

"It's about Microsoft Excel"