+ Reply to Thread
Results 1 to 6 of 6

How can I write a macro when I don't know beforehand where to put my formulas?

  1. #1
    Registered User
    Join Date
    06-25-2012
    Location
    Louisville, Kentucky
    MS-Off Ver
    Excel 2007
    Posts
    3

    How can I write a macro when I don't know beforehand where to put my formulas?

    Hello. I work for a company that requires employees to use ID badges in order to enter or leave the property. Whenever someone uses their badge, the data is sent to a spreadsheet that displays the person's name, employee ID number, the gate they used and whether they were entering or exiting (in the same cell; for example: Gate 2-In), and what time they used their badge. A new sheet starts with the start of a new day. We need to create a macro that will calculate the time an employee has spent on the property. I know how to subtract the time out from the time in in order to find the total time, but the tricky part comes when you consider the night shift; some employees will be shown checking out, without having checked in (that data being on the sheet from the day before) or vice versa, and that number changes from day to day. How can I write something that will disregard the employees who are shown as only leaving or entering, and will automatically find and do the calculations for the in-out pairs? The only way that I know how to write macros is with each formula being assigned to a specific cell, which clearly in this case will not work. I know there has to be a way, but unfortunately I have no knowledge of VBA.

    Additional details: The names are ordered alphabetically, and if the same names appears, they are ordered from earliest to latest. So supposedly, entries will all appear in pairs, time in/time out, with the exception of arriving or departing night shift employees.

    Any suggestions are appreciated! I'm clueless about what to do. Thank you!
    Attached Files Attached Files
    Last edited by JAMeyer; 06-25-2012 at 02:45 PM. Reason: Attachment

  2. #2
    Forum Contributor
    Join Date
    06-23-2010
    Location
    Iowa, United States
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: How can I write a macro when I don't know beforehand where to put my formulas?

    Welcome to the forum JAMeyer.

    There is definitely a way to do this. Someone else may be able to assist you without, but for me to write the correct code, posting a workbook would be really helpful. Can you do this?

    Steve
    A VBA novice, excited to learn!

  3. #3
    Registered User
    Join Date
    06-25-2012
    Location
    Louisville, Kentucky
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How can I write a macro when I don't know beforehand where to put my formulas?

    I just did. Thank you, for the welcome and your help! I also forgot to mention that vlookup will be used to replace "Short Term Contractor _____" with that employee's name, however I myself do not have that list at this time. I don't think it should interefere with the task at hand.

  4. #4
    Forum Contributor
    Join Date
    06-23-2010
    Location
    Iowa, United States
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: How can I write a macro when I don't know beforehand where to put my formulas?

    Hello JAMeyer,

    I have attached a workbook containing a macro that calculates the time worked for employees who checked in and out on the same day. It also makes sure that the T-TYPE = "Valid". I added a column that concatenates the employee names as well.

    Let me know if this helps.

    Steve
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-25-2012
    Location
    Louisville, Kentucky
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How can I write a macro when I don't know beforehand where to put my formulas?

    This is wonderful! Thank you so much, we really appreciate your help :D

  6. #6
    Forum Contributor
    Join Date
    06-23-2010
    Location
    Iowa, United States
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: How can I write a macro when I don't know beforehand where to put my formulas?

    Always glad to help out where I can!

+ 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