+ Reply to Thread
Results 1 to 16 of 16

Get 1st and Last Row from range

  1. #1
    Forum Contributor
    Join Date
    10-18-2015
    Location
    manila, philippines
    MS-Off Ver
    MS Office 2010
    Posts
    186

    Get 1st and Last Row from range

    Hi Experts,

    I have a spreadsheet which has several rows that shows a person's activity. and there are several person that is on the list. what I'm trying to achieve is to get only the 1st and last row for each person and transfer them to another sheet/tab. is this possible in excel through vba? I attached a sample sheet for reference, thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Get 1st and Last Row from range

    Hi,

    On the sheet "tosheet" in cell B2, enter this formula;

    Please Login or Register  to view this content.
    This can be copied to cell B4, and across the rows to C2:H2 and C4:H4

    in cell B3 of "tosheet" enter the following ARRAY formula (use CTRL, SHIFT and ENTER to confirm)

    Please Login or Register  to view this content.
    This can be copied to cell B5, and across the rows to C3:H3 and C5:H5
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Get 1st and Last Row from range

    vba
    Please Login or Register  to view this content.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Get 1st and Last Row from range

    You could use an Advanced Filter to get a list of person names, if you don't already have a list, and then loop through that using Match to get the first row and Match plus COUNTIF to get the last row
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Contributor
    Join Date
    10-18-2015
    Location
    manila, philippines
    MS-Off Ver
    MS Office 2010
    Posts
    186

    Re: Get 1st and Last Row from range

    thanks so much guys!! I used jindon's codes so I could just have it added to the vba script.

    one more thing, so now I get 2 rows per person in sheet2, is it possible to capture the person's name, the earliest start time and the latest end time?

  6. #6
    Forum Contributor
    Join Date
    10-18-2015
    Location
    manila, philippines
    MS-Off Ver
    MS Office 2010
    Posts
    186

    Re: Get 1st and Last Row from range

    thanks so much guys!! I used jindon's codes so I could just have it added to the vba script.

    one more thing, so now I get 2 rows per person in sheet2, is it possible to capture the person's name, the earliest start time and the latest end time?

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Get 1st and Last Row from range

    If the dates (col.C) are always the same,
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-18-2015
    Location
    manila, philippines
    MS-Off Ver
    MS Office 2010
    Posts
    186

    Re: Get 1st and Last Row from range

    hi jindon, thanks so much for spending time to answer my question. I'm sorry for the confusion.

    Person Task Name Date Start Time End Time Total
    PersonA task 01/01/17 9:00 AM 10:00 AM
    PersonA task 01/01/17 5:34 PM 6:00 PM

    from the example. I would want to have the duration from "9:00 AM" start time to "6:00PM" end time. I am challenged because there are 2 rows per person in my file

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Get 1st and Last Row from range

    You don't have such data in your file.

    Post a workbook with the data and the EXACT results that you want clearly showing the logic behind it.

  10. #10
    Forum Contributor
    Join Date
    10-18-2015
    Location
    manila, philippines
    MS-Off Ver
    MS Office 2010
    Posts
    186

    Re: Get 1st and Last Row from range

    Please see "tosheet" from attached file, thank you so much!
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Get 1st and Last Row from range

    No, I don't understand the logic.
    Earliest Start Time for 0001 PersonA is on row 6, 09:19:52 AM
    Latest End Time is on row 3, 09:19:52 AM

    This is based on what you said
    one more thing, so now I get 2 rows per person in sheet2, is it possible to capture the person's name, the earliest start time and the latest end time?

  12. #12
    Forum Contributor
    Join Date
    10-18-2015
    Location
    manila, philippines
    MS-Off Ver
    MS Office 2010
    Posts
    186

    Re: Get 1st and Last Row from range

    under "tosheet", person A's earliest start time is in D2 and the latest end time is in E3. Sorry if I confused you.

  13. #13
    Forum Contributor
    Join Date
    10-18-2015
    Location
    manila, philippines
    MS-Off Ver
    MS Office 2010
    Posts
    186

    Re: Get 1st and Last Row from range

    then the duration/outcome should be in column F, but since it involves 2 cells, 2 rows for that person, that's actually one of the next thing I have to figure out

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Get 1st and Last Row from range

    Then what's wrong with my first code?

  15. #15
    Forum Contributor
    Join Date
    10-18-2015
    Location
    manila, philippines
    MS-Off Ver
    MS Office 2010
    Posts
    186

    Re: Get 1st and Last Row from range

    nothing's wrong with your first code, it actually does the job in getting only the earliest and latest entry per person from the "fromsheet" to the "tosheet". what I need is after the first code to transfer the data to the "tosheet", I want to calculate the duration from the earliest start time (E3-D2), then for the next person (E5-D4), next E7-D6, and so on.

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Get 1st and Last Row from range

    Post a workbook with EXACT result that you want.
    Manually calculate the cell, if needed.

    I don't want to do a guess work to avoid more confusion.

+ 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. Replies: 4
    Last Post: 07-05-2016, 05:40 AM
  2. Replies: 9
    Last Post: 05-19-2016, 06:48 PM
  3. Replies: 0
    Last Post: 05-18-2016, 04:52 PM
  4. [SOLVED] Help! - Copy Range (Sheet1,A10:F50), Paste Range (Sheet 2,A1:F41), Offset Range & Repeat
    By cjtimmer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-30-2015, 06:27 PM
  5. [SOLVED] Count number of occurances below a range, within a range, and below a range
    By maacmaac in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-15-2013, 11:36 PM
  6. [SOLVED] Copying Active Cell-Row-Range to Other Workbook is pasting an image of copied range
    By jrtraylor in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2013, 01:08 AM
  7. send to range, popup box to input what the range should be each time/select range
    By lax2734 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2012, 01:37 AM

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