+ Reply to Thread
Results 1 to 9 of 9

Pull random rows from other sheets to summary sheet

  1. #1
    Registered User
    Join Date
    01-17-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    67

    Pull random rows from other sheets to summary sheet

    Hi folks,

    I'm trying to write code for a summary sheet which will pull the first four cells from a random rows in the other sheets in the workbook.

    So for example there will be three spreadsheets A, B and C.

    From spreadsheet A I need the first four cells from the last row
    From spreadsheet B I need the first four cells from the second last row
    From C I need the first four cells from the middle row.

    So how do I get these values from within each sheet, and then I have them pulled out automatically from another sheet.

    Would it be easier if I copied the whole row? I could do that...

    Please let me know your thoughts, many thanks,

    AR

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull random rows from other sheets to summary sheet

    Hi agentred
    Are the rows truly random or will you ALWAYS need the last row from sheet A and ALWAYS need the second last row from sheet B? How many rows are there in sheet C? How do you define "middle row"?
    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    01-17-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Pull random rows from other sheets to summary sheet

    Quote Originally Posted by jaslake View Post
    Hi agentred
    Are the rows truly random or will you ALWAYS need the last row from sheet A and ALWAYS need the second last row from sheet B? How many rows are there in sheet C? How do you define "middle row"?
    John
    Hi John, thanks for the reply.

    Well, this is how it goes... In sheet A, I have a list of how many items I bought. Then a few blank rows, and a summary row, then a few more blank rows and then another summary row.

    Within sheet A I use the COUNTA function to define a variable x which counts how many items I bought, then I just use x +3 and x + 5 for the summary rows.

    I want to pull out the summary rows, so while they'll always be x + 3 and x + 5, the value of x itself will change. Sheets A B and C are automatically created from another macro.

    I use the exact same process in sheets B and C.

    Does that explain what I'm trying to do? I hope it does, many thanks for your help,

    AR

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull random rows from other sheets to summary sheet

    Hi agentred
    I'm not overly concerned about the value of "x" (although it could be part of the solution, depending on the overall scope of your macro that creates sheets A, B & C). What I am concerned about is where do the cells live that you want to pull to the summary sheet.
    will you ALWAYS need the last row from sheet A and ALWAYS need the second last row from sheet B? How many rows are there in sheet C? How do you define "middle row"?
    The procedure needs to know where to look for the information you want to summarize. So, where will the information be on sheet A (always last row)? On sheet B (always second last row)? And on sheet C (in the middle? What does that mean)?
    John

  5. #5
    Registered User
    Join Date
    01-17-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Pull random rows from other sheets to summary sheet

    I just used the middle as an example, it's not relevant.

    I think I'll always need to pull out the last row and the fourth last row. (so if there are 10 rows, I'll need row 10 and row 6, but don't care about 7-9), Does that help? Gracias,

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull random rows from other sheets to summary sheet

    Hi agentred
    This code in the attached workbook will pull the last row and the 4th last row, cells A through D, from each worksheet in the workbook and paste them to sheet D. You gave no indication where to paste so they are sitting there in a list, one after the other.
    Please Login or Register  to view this content.
    If the lines of data you are interested in pulling are uniquely titled in any fashion, the code could be made such more versatile.
    Let me know of issues.
    John
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-17-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    67

    Re: Pull random rows from other sheets to summary sheet

    Hey,

    That works perfectly actually, thank you! It also shows me how to select cells from a variable row index, which is something I've been trying to figure out for a while.

    You're right about arrangements though, is it possible to arrange it so that it's

    "Last Row Summary"
    Sheet A's last row
    Sheet B's last row

    "Fourth Last Row Summary"
    Sheet A's fourth last row
    Sheet B's fourth last row

    It's easy to have it the other way around (Sheet A summary, Sheet B Summary) because the if function cycles through each sheet but I can't figure out how to do it otherwise. I tried replacing the .end(xlup) with fixed references but it didn't work it.

    This is just a corollary, the main part is done and you have my most sincere gratitude,

    AR

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull random rows from other sheets to summary sheet

    Hi AR
    I'll take a look at this
    You're right about arrangements though, is it possible to arrange it so that it's

    "Last Row Summary"
    Sheet A's last row
    Sheet B's last row

    "Fourth Last Row Summary"
    Sheet A's fourth last row
    Sheet B's fourth last row
    Probably need to cycle through the procedure twice. I'll get back to you.
    John

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull random rows from other sheets to summary sheet

    Hi AR
    Try this code
    Please Login or Register  to view this content.
    It cycles through the worksheets twice to first pull the last row and then to pull the fourth last row. You didn't mention anything about inserting a line between the two summaries; let me know of issues.
    John

+ 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