+ Reply to Thread
Results 1 to 18 of 18

Find all entries in a range and tally numbers based on codes in adjacent fields

  1. #1
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Find all entries in a range and tally numbers based on codes in adjacent fields

    Hi All

    Hoping to get some help for this little issue. I am working on a rostering template for work and wanting to get some assistance with the final stage. The worksheet is as follows.

    Worksheet "Week 1" has the following
    The names and shift codes are in the range B1:W115
    There is then a list of all staff names in Column X
    Then a tally of the hours would be put into Column Y

    Worksheet "Data" has the following
    The list of shift codes in column J
    The hours each shift code represents in column K

    So the idea is to find all of the names (as they are entered) in range B1:W115 that are the same (so all the Freddy Mercury's for example) and then look at the shift codes in the cell next to them next to them (if the name was in A1 for example the shift code would be in cell B1 of the same worksheet). Compare those shift codes to those in column J of worksheet "Data" to find the hours in column K of worksheet "Data"
    and then in column Y next to the person's name in column X add the hours up for all the entries on the worksheet.

    Here is the file attached
    Example template.xlsm

    Regards

    Rey2

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

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello reynastus2,

    The macro below has been added to the attached workbook. You can run the macro by using Alt+F8 to display the macro dialog and click StaffHours and OK.

    The macro expects the sheet names to be "Week 1", "Week 2", "Week 3", and "Week 4". If you change the sheet names, you must change them in the macro also.

    The hours are copied to the table on "Week 1" next to column "X". If you change the location of this table then the macro will need to updated.

    Have a look a let me know if this what you wanted.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hi there
    Yes! that is doing what I am after... Only question is there a way to get it to update automatically? I tried calling the macro on sheet change and it was throwing errors up "method 'find' of object 'range' failed as a run time error when placing it in the worksheet change property of the worksheet.

    Regards

    Rey2

  4. #4
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    I actually spoke a bit too soon ... The code works really well for the Monday to Friday entries but then doesn't see the Saturday or Sunday entries.

    I added the Saturday and Sunday entries into the day array as such
    Please Login or Register  to view this content.
    however when I enter something into the sunday box I get an object required error number 424.

    Thank you for all your help.

    Rey

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

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello reynastus2,

    This took awhile longer that I had planned. But, it works correctly and it is fast.

    The macro has been rewritten. Each weekly worksheet now calls the macro when a cell is changed and updates the hours.

    Here is the revised macro with annotations ...

    Module4 Macro Code
    Please Login or Register  to view this content.
    Worksheet_Change() Event Macro Code for the Weekly Sheets
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Thank you very much for all the help.

    Sunday isn't working. And well this is waay beyond my abilities to figure out why...


    Thanks for all the support!
    Rey

  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,258

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello Rey,

    The data validation in Sunday does not contain any Staff names. I did not change them because I was not sure what Staff names should be there.

    Change your validation lists in the Sunday table and it will work correctly.

  8. #8
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    I thought about that when I checked it out and to no avail. I thought it might have been where the table was located as well and so changed that as well. Still no luck ... I have attached the version that you uploaded with the only change being the data validation.

    Once again thanks for the help and I am apparently not allowed to spread more reputation for your assistance.

    Example template ver 3.xlsm

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

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello Rey,

    I had to move the Sunday table below the Saturday table. The macro validates the staff names starting in column "E". If the names for the day don't start in column "E" then it skips those cells.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Thats what I thought would happen ... the curious thing is that sunday PM wont work. Ive done some cell merging etc that makes the saturday PM column staff name and shift codes the same (I and J). Saturday PM works correctly. Sunday doesn't

    Example template ver 3b.xlsm

  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,258

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello Rey,

    Still trying to figure this out. Just does not make sense.

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

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello Rey,

    Still trying to figure this out. Just does not make sense.

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

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello Rey,

    Okay, I just decided to replace the Sunday table with the Saturday table. Now it works!

    Perhaps the worksheet become corrupted when the I moved it the Sunday table the first time.

    Anyway, it working now for Sunday AM and PM.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Thanks so much Leith

    Sorry I didn't get back to you earlier ... got massively busy at work and I don't actually use a PC for my job that much but this is awesome!

    Thanks heaps

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

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello Rey,

    Don't worry, we all get busy time to time. The important thing is that is it finally working for you.

    Should we wait or can this be marked as solved?

  16. #16
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hi Leith

    I have done a little creative editing to your code .. Basically commented out a couple of things to allow column B and C to be included and everthing still looks good. Those columns are included in the daily worksheet and there were evening shifts located under them so I changed their appearance and brought them into line with the other cells and how the macro is searching and finding for things.

    but other wise Yes solved! Thanks heaps.

    Rey

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

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Hello Rey,

    Impressive, usually when a macro gets altered then something happens that isn't expected. Good job!

  18. #18
    Registered User
    Join Date
    11-04-2014
    Location
    NSW Australia
    MS-Off Ver
    2013
    Posts
    29

    Re: Find all entries in a range and tally numbers based on codes in adjacent fields

    Yeah well it kind of did that a little but I am actually ok with reading through code and having it make sense, especially when the code has enough comments through it to help explain the functions. Basically just commented out the sections that were stuffing up and expanding the offset to include the desired columns. It still functions and is quite quick (when compared to the first iteration of your code) but does take a bit longer ... then again I am not the one using this all the time so yeah not too bad...

    Just putting in some final touches (dynamic named range for the X column and then camera section for the other weeks in the worksheet so that when using the sheet you don't have to keep clicking back to week 1 to get the tally of hours) then theres a vlookup that I am planning on putting into another worksheet that will hopefully populate a roster as such for each person... we'll see how that goes.

    Rey

+ 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. using SUMIF based on entries in adjacent column.
    By benjaminblumberg in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-06-2014, 08:42 PM
  2. [SOLVED] How to search and remove a series of entries based on adjacent values.
    By Excel Trier in forum Excel General
    Replies: 16
    Last Post: 02-15-2014, 01:28 AM
  3. Replies: 4
    Last Post: 08-11-2013, 12:58 AM
  4. Replies: 1
    Last Post: 03-08-2011, 11:51 AM
  5. Tally of Fields with Entry
    By jimmihundreds in forum Excel General
    Replies: 2
    Last Post: 06-15-2010, 12:38 PM

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