+ Reply to Thread
Results 1 to 11 of 11

Searching for sheet, counting and filling in data

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Searching for sheet, counting and filling in data

    I have this challenge I would like some help with.
    After thinking about the task at hand, I found that I do not have the right skills with VBA to get it down.

    Please see the attached file.

    On sheet 1, the rows represent the date in a month, and the columns represent other sheets in the workbook, with the name of the sheet in the header.
    On the sheets that have a name similar to the headers, B1:D1 in the example, there are columns with month, day and hour.

    I would like a subroutine that does something like this:
    1. Loop trough row 1 on sheet1 and check if it finds a sheet with a name corresponding to the value in the checked cell.
    2. If it finds a sheet - count the number of lines of each day in that sheet (1, 2, 3 [...])
    3. Fill in the count of items per day in the corresponding cell matching the column for the respective sheet name and the row of the counted day.
    4. When it is finished with the first column that matches, start from step one and repeat for each matching sheet.

    I would also like to be able to add more columns that correspond to a sheet name in Sheet1 at a later stage.

    Thank you so much for your help in advance!

    Best regards,
    Knut
    Attached Files Attached Files

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Searching for sheet, counting and filling in data

    Hi Knut, add the following into a module and run it
    Please Login or Register  to view this content.
    There's no doubt a more efficient way of doing this but I think it does what you require it to do.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Searching for sheet, counting and filling in data

    Quote Originally Posted by Mordred View Post
    There's no doubt a more efficient way of doing this but I think it does what you require it to do.
    Hi Mordred, you're completely right. This does what I require it to do. Thank you very much!

    But after trying your formula I realized that it should also set 0 if the count is 0. That does not seem to happen right now.
    Probably an easy fix?

    /Knut

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Searching for sheet, counting and filling in data

    This ought to do it
    Please Login or Register  to view this content.

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Searching for sheet, counting and filling in data

    no that won't quite do it, give me a couple minutes

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Searching for sheet, counting and filling in data

    Alright, the following seems to be working with your new requirements
    Please Login or Register  to view this content.

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Searching for sheet, counting and filling in data

    Did this help your problem? It's been noted that you have returned since the last post but haven't managed to let us know if your issue is resolved. As a matter of courtesy perhaps you'd like respond to those that have taken time out of their day to help you for free?

    I'm sure you can see that you're more likely to receive help a second time if you are remembered as someone who has offered thanks in the past. That's just human nature.
    Last edited by Mordred; 07-04-2013 at 02:58 PM.

  8. #8
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Searching for sheet, counting and filling in data

    I'm so terribly sorry, Mordred. It was not intentional to not acknowledge your efforts straight away. I take pride in being generous with offering thanks and praise whenever someone is helping me out, but I realize that I've not been that good at it here at these forums. Please accept my sincerest apologies. I will promise work on my not desirable habits - you guys at this forum are really passionate about what you do, and you deserve proper credits for persevering with people like me, that are complete novices when it comes to VBA. The help and efforts you and the other users at this forum put into other persons challenges and problems with Excel really make this a thriving community, where it is easy to get assistance when needed. And that is something I really appreciate.

    With regards to your proposed solution, I have unfortunately not had time to test it yet. I will implement it and test it tomorrow, and get back to you as soon as it is tested.

  9. #9
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Searching for sheet, counting and filling in data

    It's not praise I look for knutfh, it's closure. Thanks for coming back and letting me know that you haven't tested it yet. I appreciate that.

  10. #10
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Searching for sheet, counting and filling in data

    Now Mordred, I've had the chance to test your code. It did everything I wanted, and then some. A bug caused it to fill 0 into the entire column to the left of the column being processed.

    I changed the last for each statement, so that it will only affect the desired column. I went from:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    I would not have figured this out without your help! Thank you so much!

    I include the final version of the routine here, for others reference:

    Please Login or Register  to view this content.

  11. #11
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Searching for sheet, counting and filling in data

    Nicely done knutf, sorry about the column-1 slip up but I didn't really test that part thoroughly enough when I should have. Good job catching that and changing it though.

+ 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