LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Adding Cells and Indexing

If you like UDFs this one runs about 3 times faster than the array formula.

Option Explicit
Option Base 1
Public Function GetDate(theDates As Range, theData As Range, startDate As
Variant, MagicNumber As Variant) As Variant

Dim vStartRow As Variant
Dim vData As Variant
Dim j As Long
Dim dTot As Double

On Error GoTo Finish
vStartRow = Application.Match(startDate, theDates, 1)

vData = theData.Cells(vStartRow, 1).Resize(MagicNumber, 1).Value2

For j = 1 To MagicNumber
dTot = dTot + vData(j, 1)
If dTot = MagicNumber Then
GetDate = theDates.Cells(vStartRow + j - 1, 1)
Exit For
End If
Next j
Finish:
If GetDate = 0 Then GetDate = CVErr(xlErrNA)
End Function

Charles
__________________________________________________
Outlines for my Sessions at the Australia Excel Users Group
http://www.decisionmodels.com/OZEUC.htm

"Archengineer" wrote in message
...
Ok, I forgot to explain the information in the cells adequately. The data
in
the second column is a random number from 1 to 24 and both columns have an
infinite number of cells (one new cell date and the corresponding data is
added each day). I am going to pick a "number" cell in the second column
based on the date in the first cell. From there I will add consecutive
cells
in the second column until they total 336 or greater. Once I reach at
least
336 the output must tell me the date at which it was reached. I hope that
explains it better.


"T. Valko" wrote:

Here's an array formula**.

What if the total isn't *exactly* 336?

=INDEX(A1:A20,MATCH(TRUE,SUBTOTAL(9,OFFSET(B1,,,RO W(INDIRECT("1:"&ROWS(B1:B20)))))=E1,0))

Where E1 = 336

If the total of column B is <336 then the formula returns #N/A

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER)

--
Biff
Microsoft Excel MVP


"Archengineer" wrote in message
...
I have two columns. One column contains dates the other contains
numbers
from 1 to 24. I need to add consecutive cells in the second column
until
I
total 336 and then output the date at which that occurs. I've been
racking
my brain on how to do this and I think there's any easy answer, but I
can't
find it. Can someone help me?






 
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
Tab indexing ibgolfn Excel Discussion (Misc queries) 2 January 16th 08 12:04 AM
Indexing M&M[_2_] Excel Discussion (Misc queries) 1 July 13th 07 07:10 PM
Indexing of Name Charlie Excel Worksheet Functions 1 April 5th 06 01:33 PM
Indexing Referenced Cells ForMyACDs Excel Discussion (Misc queries) 0 February 23rd 06 09:08 PM
Indexing a row ecohen1 Excel Worksheet Functions 6 July 20th 05 06:11 PM


All times are GMT +1. The time now is 11:13 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"