PC Review


Reply
Thread Tools Rate Thread

Adding Cells and Indexing

 
 
Archengineer
Guest
Posts: n/a
 
      8th Feb 2008
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?
 
Reply With Quote
 
 
 
 
T. Valko
Guest
Posts: n/a
 
      8th Feb 2008
Here's an array formula**.

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

=INDEX(A1:A20,MATCH(TRUE,SUBTOTAL(9,OFFSET(B1,,,ROW(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" <(E-Mail Removed)> wrote in message
news:CC5357D6-EBFE-4025-839C-(E-Mail Removed)...
>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?



 
Reply With Quote
 
Charles Williams
Guest
Posts: n/a
 
      9th Feb 2008
The numbers 1 to 24 only total to 300, and if you extend the series you
never get to exactly 336.

I suggest you add a helper column (C) that calculates your running total of
column B so that its easier to see whats happening

then for an exact match to 366 use the formula (not an array formula)
=INDEX($A$1:$A$24,MATCH(E1,$C$1:$C$24,0),1)

To get the first date where the running total exceeds 366 use
=INDEX($A$1:$A$24,MATCH(E1,$C$1:$C$24,1)+1,1)

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

"Archengineer" <(E-Mail Removed)> wrote in message
news:CC5357D6-EBFE-4025-839C-(E-Mail Removed)...
>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?



 
Reply With Quote
 
Archengineer
Guest
Posts: n/a
 
      11th Feb 2008
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,,,ROW(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" <(E-Mail Removed)> wrote in message
> news:CC5357D6-EBFE-4025-839C-(E-Mail Removed)...
> >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?

>
>
>

 
Reply With Quote
 
Charles Williams
Guest
Posts: n/a
 
      11th Feb 2008
Here is a small modification to Biff's array formula:

assuming that
DateRange is a dynamic range for the Date column (first column)
The Date column is in ascending date order (if not change the 1 in each
MATCH function to 0)
DataNumbers is a dynamic range for the numbers column (second column)
The lowest possible number in DataNumbers is 1
StartDate is the name of the cell containing the date you want to pick in
the date column
GENumber is name of the cell containing the magic 336 number

=INDEX(OFFSET(DateRange,MATCH(StartDate,DateRange,1),0,GENumber,1),MATCH(TRUE,SUBTOTAL(9,OFFSET(OFFSET(DataNumbers,MATCH(StartDate,DateRange,1),0,GENumber,1),,,ROW(INDIRECT("1:"
& GENumber))))>=GENumber,0),1)

Needs entering with CSE

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

"Archengineer" <(E-Mail Removed)> wrote in message
news:43371926-9BD6-4D8C-A527-(E-Mail Removed)...
> 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,,,ROW(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" <(E-Mail Removed)> wrote in message
>> news:CC5357D6-EBFE-4025-839C-(E-Mail Removed)...
>> >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?

>>
>>
>>



 
Reply With Quote
 
Charles Williams
Guest
Posts: n/a
 
      11th Feb 2008
Oops, forgot to subtract 1 for the starting offset

=INDEX(OFFSET(DateRange,MATCH(StartDate,DateRange,1)-1,0,GENumber,1),MATCH(TRUE,SUBTOTAL(9,OFFSET(OFFSET(DataNumbers,MATCH(StartDate,DateRange,1)-1,0,GENumber,1),,,ROW(INDIRECT("1:"
& GENumber))))>=GENumber,0),1)

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

"Charles Williams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here is a small modification to Biff's array formula:
>
> assuming that
> DateRange is a dynamic range for the Date column (first column)
> The Date column is in ascending date order (if not change the 1 in each
> MATCH function to 0)
> DataNumbers is a dynamic range for the numbers column (second column)
> The lowest possible number in DataNumbers is 1
> StartDate is the name of the cell containing the date you want to pick in
> the date column
> GENumber is name of the cell containing the magic 336 number
>
> =INDEX(OFFSET(DateRange,MATCH(StartDate,DateRange,1),0,GENumber,1),MATCH(TRUE,SUBTOTAL(9,OFFSET(OFFSET(DataNumbers,MATCH(StartDate,DateRange,1),0,GENumber,1),,,ROW(INDIRECT("1:"
> & GENumber))))>=GENumber,0),1)
>
> Needs entering with CSE
>
> regards
> Charles
> __________________________________________________
> Outlines for my Sessions at the Australia Excel Users Group
> http://www.decisionmodels.com/OZEUC.htm
>
> "Archengineer" <(E-Mail Removed)> wrote in message
> news:43371926-9BD6-4D8C-A527-(E-Mail Removed)...
>> 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,,,ROW(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" <(E-Mail Removed)> wrote in message
>>> news:CC5357D6-EBFE-4025-839C-(E-Mail Removed)...
>>> >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?
>>>
>>>
>>>

>
>



 
Reply With Quote
 
Charles Williams
Guest
Posts: n/a
 
      11th Feb 2008
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" <(E-Mail Removed)> wrote in message
news:43371926-9BD6-4D8C-A527-(E-Mail Removed)...
> 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,,,ROW(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" <(E-Mail Removed)> wrote in message
>> news:CC5357D6-EBFE-4025-839C-(E-Mail Removed)...
>> >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?

>>
>>
>>



 
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
Windows Search: with no disks enabled for indexing, what is it indexing? Jeremy Nicoll - news posts Windows XP Basics 11 21st Feb 2009 10:14 PM
Folders do not display in Indexing Options / Indexing Locations =?Utf-8?B?R3Vz?= Windows Vista File Management 0 19th Oct 2007 10:09 PM
indexing problem when adding row =?Utf-8?B?QW50?= Microsoft ADO .NET 1 16th Oct 2006 05:26 AM
Indexing Referenced Cells =?Utf-8?B?Rm9yTXlBQ0Rz?= Microsoft Excel Misc 0 23rd Feb 2006 09:08 PM
Lookout v1.2 - Super indexing and search available again [was Re: Outlook plugin for email archive indexing & searching?] BillR Freeware 0 26th Aug 2004 01:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:28 AM.