+ Reply to Thread
Results 1 to 4 of 4

Macro to calculate Length of Stay

  1. #1
    Registered User
    Join Date
    04-24-2014
    Location
    Glendale, Colorado
    MS-Off Ver
    Excel 2013
    Posts
    49

    Macro to calculate Length of Stay

    Hello!
    We calculate a metric called Length of Stay which subtracts the date an animal arrived at the shelter from the date it left. It works fine to do it this way except in cases where animals arrive and must be fostered. When they are fostered the time they spend in a foster home must be subtracted from total LOS, complicating the calculation.

    We use a method of data entry which outcomes animals heading into a foster home as OUTCOME_TYPE: FOSTER. When that animal is done fostering, we do another Intake as INTAKE_TYPE: FOSTER. So an animal could have multiple entries as it goes out twice and comes in twice.

    I attached a list of 4 cats who were fostered plus one (KARA) who was not, for a total of 5 cats. I would like a macro to calculate the number of days between the animals' arrival and final outcome in column G. In the 4 out of 5 cases attached where the animal went to foster (Outcome Type = FOSTER) and came back from foster (Intake_TYPE = FOSTER) this calculation should subtract the number of days spent in foster from the final LOS calculation. So that first of two outcome dates would be subtracted from the second Intake Date. For KARA, the macro should calculate just the time between her intake as a TRANSFER and her outcome as an ADOPTION- or 13 days.

    Ideally, the macro could simplify the multiple entries and replace 3 rows with one for each animal, so for CARTER it could go from this

    ANIMAL_ID ANIMAL_NAME INTAKE_DATE OUTCOME_DATE OUTCOME_TYPE INTAKE_TYPE LOS:
    A0711031 CARTER 7/5/2015 12:00:00 AM 7/5/2015 12:00:00 AM FOSTER TRANSFER
    A0711031 CARTER 9/3/2015 12:00:00 AM 9/23/2015 12:00:00 AM FOSTER FOSTER
    A0711031 CARTER 10/14/2015 12:00:00 AM 11/5/2015 12:00:00 AM ADOPTION FOSTER


    to something like this:
    ANIMAL_ID ANIMAL_NAME INTAKE_DATE OUTCOME_DATE OUTCOME_TYPE INTAKE_TYPE LOS:
    A0711031 CARTER 7/5/2015 12:00:00 AM 11/5/2015 12:00:00 AM ADOPTION TRANSFER 123


    I think the foster stint could be recognized by sorting by intake date date, and then looking for entries where FOSTER is present in Column E in the first row and then column F in the following row but I am not sure how to do this so that it can also calculate LOS for animals which were not in this foster cycle. Or how to manage the simplifying need from 3 to 1 rows.

    Thank you so so much in advance for any help.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Macro to calculate Length of Stay

    I used helpcolumns to calculate the days.

    after that a pivot table.

    see the attached file.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    04-24-2014
    Location
    Glendale, Colorado
    MS-Off Ver
    Excel 2013
    Posts
    49

    Re: Macro to calculate Length of Stay

    Thank you. I was really hoping for a macro that would insert the LOS in the sheet as it is, is it possible you could assist with that?

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Macro to calculate Length of Stay

    not for me, maybe another forummember.

    Although I would solved it the way I showed it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Multiple Regression to Model Length of Stay
    By sccrbrg in forum Excel General
    Replies: 1
    Last Post: 04-09-2015, 09:05 PM
  2. Calculating the Average Length of Stay for a given month
    By jbh001 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-11-2015, 03:41 PM
  3. Repeat Calculation At Length & Calculate Lowest Value At Length
    By sanju2323 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-17-2013, 09:19 AM
  4. [SOLVED] Macro or code to calculate the length of time a vehicle spends in a an area
    By AlexRoberts in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2012, 01:56 AM
  5. Replies: 4
    Last Post: 09-10-2009, 08:58 AM
  6. Date to fill and stay same - also to calculate 1 month
    By tstorzuk in forum Excel General
    Replies: 11
    Last Post: 07-17-2008, 02:10 PM
  7. How do you make the auto calculate setting stay on manual permanently?
    By anasttin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2006, 08:10 PM

Tags for this Thread

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