+ Reply to Thread
Results 1 to 5 of 5

Insert Comment in Cells Automatically When Countif Returns a Value

  1. #1
    Registered User
    Join Date
    07-20-2007
    Location
    Nashville, TN
    Posts
    3

    Insert Comment in Cells Automatically When Countif Returns a Value

    Hello all, it's my first time to post, so thanks in advance for your help and patience as this is a pretty hard request to describe.

    I'm am building an Excel workbook that tracks changes to a retail chain's headcount. Headcout goes up and down via new hires and terminations (events) that happen in different locations, different dates, and with different rep types. I receive a transaction log weekly in Excel from our database that outlines each event, which includes the person's name, their ID number, rep type, and date it occurred (The Events Log tab in the attached workbook)

    Each retail store has it's own tab in the same workbook (Friendswood, Houston, etc). Each store's tab shows the beginning headcount for each week, terminations, new hires, and an ending headcount for each week with those events figured in...all for each rep type. Terminations get negative numbers as they take away headcount, new hires get positives. I get the values for both of these events to populate in the site tabs by doing a bunch of countifs that pull from the Events Log.

    My question here is twofold:
    First, I'm stumped and need to have some help writing a process in VBA that would go to each store's tab, look and see if there are any values for Terminations and New Hires for all rep types, and if there is a value there other than zero, it needs to go back to the Events log and pull the name and effective date for the rep that was counted in the countif that populated the cell (ex. at Friendswood (cell B7), there was 1 termination the week of 6/30-7/6 for FT Regular Sales Specialist, I need to have a comment inserted in that cell that identifies the person's name and the effective date of the termination that caused that -1. If that number was -2 or -3, I would need each name and date listed in the comment as well. If the event has a value of zero, no comment needs to be inserted. I need it to do this for every week, every rep type, and for all events (terminations and new hires) I basically want to see who is terminating or brought on as a new hire each week with these comments at each location. Comments have to be used in this sheet to conform to our company's reporting structure (but if you have other suggestions to display this data, I'll certainly listen to it)

    Second, I used some pretty primitive Countifs to populate the events in each location's tab, if there is a better/easier way to do it, I'd love your advice.

    In reality, in my actual file I am using...I have 151 different location tabs, 5 different events that can happen, 4 different rep types, and 52 different weeks that it all can happen in. I really need something that can be easily replicated to each location's tab, and would have the ability to update itself when new events are added on a weekly basis.

    I hope I have been clear on what I need, if not please let me know and I will clarify. Thanks all!!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-28-2005
    Location
    WI, USA
    MS-Off Ver
    Office XP/2003
    Posts
    95

    Questions

    I have two questions before I start chipping away at this:

    1) Are entries going to be deleted from the Event Log, or once there, they'll always be there?

    2) Do you want it to extract names from only the most current week or to redo every single week each time the code is run (in case of a backdated entry)?

    And other than the countif formulas, I can't think of a better way to do that either, unless you incorporate that into the code.

  3. #3
    Registered User
    Join Date
    07-20-2007
    Location
    Nashville, TN
    Posts
    3
    Thanks Caligula for sifting thru all this mess! Here are your answers:

    1. I plan on keeping the data in the log for ~13 weeks, then I'll just go into each site's tab and copy, paste special, values and comments to hardcode them in so the log can be shortened. If this causes serious issues then I can just keep the log as is.

    2. I'd like for it to run all weeks to insert any backdating that may happen.

    Thanks again!

  4. #4
    Registered User
    Join Date
    05-28-2005
    Location
    WI, USA
    MS-Off Ver
    Office XP/2003
    Posts
    95
    Ok, so I believe I've got it. It puts a comment in each of the cells, provided that week started less than 100 days ago (2 days over 14 weeks). This should work on any number of worksheets, with any number of positions, provided it's in the same format as this is. I add to fix a few spelling errors to get it matching correctly (line 38 I believe). I used the current sheet's F2 cell as a temporary holding cell; you can replace it with a different cell or a DataObject if you want (I just don't like using DataObjects unless I have to).

    I pasted the code in a CommandButton on the main page and tested it; it seems to work. As you can see, there's a variable entry for each "event," a line where the remaining events in that column is checked, a routine to find people that went through that event, and a select case statement for that event. That should help you work through the rest of your programming...

    Let me know if you need anything else,
    Chris

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-20-2007
    Location
    Nashville, TN
    Posts
    3
    All hail Caligula! I'll see if I can insert it into my real working workbook and get it going. Thanks again....I'll let you know if I get stumped.

+ 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