+ Reply to Thread
Results 1 to 10 of 10

Use dates to define a set of data?

  1. #1
    Registered User
    Join Date
    01-28-2007
    Posts
    9

    Use dates to define a set of data?

    My first post here I'm afraid i've hit a snag in a project I'm doing at the moment, which is essentially a logbook of medical cases I've been involved in.

    I've created a spreadsheet and a summary form for that spread sheet made up of lots of functions extracting data from the spreadsheet. What I want to do now is to have way by which a person can type in a start date and end date, and the summary functions then only execute on spreadsheet cells that are between those two dates.

    I guess what I mean is that I want to define the range in which the functions extract the necessary data by the use of dates, which can be altered at will.

    Does that make any sense?! Any help will be very very gratefully received

  2. #2
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    "I guess what I mean is that I want to define the range in which the functions extract the necessary data by the use of dates, which can be altered at will"

    what functions?

    If the date is part of the record then you can easily use two ifs to determine if the record is in the date range.
    not a professional, just trying to assist.....

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Could you use a input box and filter

    Try the below

    Please Login or Register  to view this content.
    Change Field 2 to column with date

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  4. #4
    Registered User
    Join Date
    01-28-2007
    Posts
    9
    Quote Originally Posted by duane
    "I guess what I mean is that I want to define the range in which the functions extract the necessary data by the use of dates, which can be altered at will"

    what functions?

    If the date is part of the record then you can easily use two ifs to determine if the record is in the date range.
    Thanks for the input. The date is part of the record - all the records are date labelled. One of the (myriad) of functions is this, for example:

    =COUNTIF('Aug 05'!G2:G341,"ENT")+COUNTIF('Aug 06'!G2:G301,"ENT")

    where I count the number of columns in sheets Aug 05 and Aug 06 that are labelled ENT. What I want to do is count the columns for a particular range of dates (defined in column A in each spread sheet (cell A2 onwards)). More importantly I want to be able to change the range of dates when needed.

  5. #5
    Registered User
    Join Date
    01-28-2007
    Posts
    9
    Thanks VBA Noob for the idea of VB - I'm thinking about it, but part of the problem is that I need to return a number in a summary sheet. The forumla above is just one of the many:

    A snapshot is here

    Where the formula is contained in cell B8.

    Hope that makes things clearer.

  6. #6
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    no need for vba - just sub the cells with the dates in below, and also the column of dates

    =sumproduct(('Aug 05'!G2:G341="ENT")*(firstdate>=range with dates)*(seconddate<=range with dates))+

    same thing for other sheet


    COUNTIF('Aug 06'!G2:G301,"ENT")

  7. #7
    Registered User
    Join Date
    01-28-2007
    Posts
    9
    duane: Wow!! Fantastic, that seems to have done the job! Thanks so very very much!

    Somehow I've also managed to get this to work with another more complicated formula. From the image I linked to, you may notice the age range options. Basically, I've got a formula that tells me how many patients on an ENT list, say, were aged between 1 - 5. After using your suggested method, where L3=date1 and H3=date2:

    =(SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>=1))-SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>5)))*((L3>='Aug 05'!A2:A341)*(H3<='Aug 05'!A2:A341))+(SUMPRODUCT(--('Aug 06'!G2:G341=A8),--('Aug 06'!C2:C341>=1))-SUMPRODUCT(--('Aug 06'!G2:G341=A8),--('Aug 06'!C2:C341>5)))*((L3>='Aug 06'!A2:A341)*(H3<='Aug 06'!A2:A341))

    That's one huge formula! Is this really the main way of achieving this?

    On a side note, if I am to copy this into various cells, is it possible to ensure that just the A8 label increments by one to A9, rather than all the cell labels?
    Last edited by semper_si; 01-28-2007 at 07:22 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    to answer your question, sure, just change all other adresses and rabges to absolute (change 'Aug 06'!G2:G341 to 'Aug 06'!$G$2:$G$341 for example)

    also, you can make all the sumproduct "*"'s ",--" if you like

  9. #9
    Valued Forum Contributor
    Join Date
    07-11-2004
    Posts
    851
    oh, you can also combine the age range into one sumproduct rather that the difference of two - but now I'm confused, why do you only have the L3>= term on the >5 criteria?

    =(SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>=1)),--('Aug 05'!C2:C341<=5),--(L3>='Aug 05'!A2:A341))
    +
    (SUMPRODUCT(--('Aug 06'!G2:G341=A8),--('Aug 06'!C2:C341>=1),--('Aug 06'!C2:C341<=5),--(L3>='Aug 06'!A2:A341))

  10. #10
    Registered User
    Join Date
    01-28-2007
    Posts
    9
    Thanks sooo much! I'll play around with the forumlae tonight, and that $ may just save me from anymore headaches.

    I think the reason the L3>= term looks like it only covers the >5 range is because I perhaps naievley believed that by surrounding:

    SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>=1))-SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>5))

    with brackets:

    ((SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>=1))-SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>5)))

    then the SUMPRODUCT formula for the date range would enact on all within the first set of brackets, hence:

    =(SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>=1))-SUMPRODUCT(--('Aug 05'!G2:G341=A8),--('Aug 05'!C2:C341>5)))*((L3>='Aug 05'!A2:A341)*(H3<='Aug 05'!A2:A341))

    In any case, your suggestion looks far more elegant. I think I need to go and read more about what SUMPRODUCT does

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1