+ Reply to Thread
Results 1 to 15 of 15

Pulling information from a spreadsheet

  1. #1
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Pulling information from a spreadsheet

    Hi folks, I got great help just now on the first part of this project and am hoping to get lucky again. I attached a workbook. This is traffic count data. I need help pulling information from spreadsheet named HourTotals.

    The data is in cells H2:AE366, it is 24 hours wide by 360 days long. I need to search that range for the highest number and in addition to the number get the corresponding date from the date_ column and the hour from the corresponding hr_X column and paste that information into another spreadsheet and repeat that process for say 500 values.

    No problem right? Any help is greatly appreciated. Thanks.
    Attached Files Attached Files
    Last edited by TrafficGuy; 01-07-2009 at 04:49 PM.

  2. #2
    Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    An hour due East of Cowtown Ohio
    MS-Off Ver
    2010
    Posts
    421
    Question...you want to know the dates and times of the top 500 counts right?

  3. #3
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39
    Yes, and I need to be able to sort the data in a value decending fromat so I can graph it. Thank you for your help.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    See attached.

    First you need to list the Maximums, in case there are duplicates. Then you extract the data.
    Attached Files Attached Files
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  5. #5
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39
    OK I can use the MAX function to find the max but then what? Could I use a for each next to loop through the range and find the next value? I'm not that good, I guess I would have to somehow ignore the cell containing the MAX value and then find the next MAX? Any ideas?

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Did you review my attachment? Does it not do as you required?

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello TrafficGuy,

    The Attached workbook has a button on the worksheet Results to run the macro at anytime. The first 500 rows contain the number, dates, and hours from highest to lowest number in columns A,B, and C. You can use rows 1 to 500 for chart series.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  8. #8
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39
    Sorry NBVC you are correct I did not see the attachment. I haven't used this forum often and am learning. Thanks again. I'm checking it out right now.

  9. #9
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39
    Thakns for the help NBVC and Leith, I downloaded the file that NBVC posted and I don't have any code in it. Not sure if the code is not actually there or, more likely, my employer blocks all code in files. Is the code that Leith posted the only code in this spreadsheet? If so I can just copy it and put it back in the spreadsheet.

    Thanks again.

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    My solution does not use VBA code.. only formulas in Sheet1

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello TrafficGuy,

    Yes, the code posted is all that appears in the workbook.

    Sincerely,
    Leith Ross

  12. #12
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39
    OK, now I believe I understand now. Two different approaches to the same problem, awesome.

    I was confused earlier by the code posted by Leith Ross, I thought he was referring to the file posted by NBVC.

    Thank you both very much for the help.

  13. #13
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    I can see how you misunderstood... Leith forgot to attach his sample workbook when posting his code, so you assumed he meant my workbook...lol.

    Anyways, hope one of them works for you.

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    From PM:

    Hi NBVC, thank you for the help. I hate to bother you and if you don't have time for this I understand but I could really use some help understanding your formula. I have been reading the help on arrays and indexes but I still can't completely understand how one of your formulas works. Could you please parse out the following formula for me and explain how it actually works?

    Thanks

    =INDEX(HoursTotal!B$2:B$366,SMALL(IF(HoursTotal!$H$2:$AE$366=$A2,ROW(HoursTotal!$H$2:$AE$366)-ROW(HoursTotal!$H$2)+1),COUNTIF($A$2:$A2,$A2)))
    First I extracted the largest 500 values and listed them in descending order in column A using this formula:

    Please Login or Register  to view this content.
    copied down.

    Note: Some are repeats.. so you need to extract multiple matches, hence the use of the following formula instead of a simple Vlookup (which would only return first match found for those repeated numbers).


    Please Login or Register  to view this content.

    It uses the Index() function which requires you to index the table or column to extract from (in this case HoursTotal!B$2:B$366, to extract the dates and it requires the Row number to extract from which is gotten from this part: SMALL(IF(HoursTotal!$H$2:$AE$366=$A2,ROW(HoursTotal!$H$2:$AE$366)-ROW(HoursTotal!$H$2)+1),COUNTIF($A$2:$A2,$A2))

    The Small() function just allows us to step up and extract one match at a time, starting from the first match found. It will extract only if a there is a matching time found for time in $A2 of Sheet1 in the range HoursTotal!$H$2:$AE$366 and then it will return the corresponding row number within the range. The -ROW(HoursTotal!$H$2)+1 is added for robustness (incase you insert rows above, then the result won't skew).

    The last COUNTIF($A$2:$A2,$A2) is the k factor for the Small() function, which is like a step factor in a For...next loop in VBA. So as you copy down the column it counts how many times the Max Time in that row has appeared in the list and uses that as the k factor to determine which match to find. When a new Max number comes up, then it reverts the Count back to 1...

    The CSE confirmation is because it is an array formula and you have to confirm with those keys to make these formulas work.

    To extract the hours, which are listed horizontally in your table, you need to change the Indexed range to the new range, i.e. HoursTotal!$H$1:$AE$1 and you need to find what columns match the Max Numbers to return Column Number to extract from...hence change ROW() function to COLUMN() function.

    Hope this helps you.

  15. #15
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39
    Thank you very much for your help.

+ 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