+ Reply to Thread
Results 1 to 4 of 4

Time/Date Capture when data is entered and multi conditional

  1. #1
    Registered User
    Join Date
    01-26-2015
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Time/Date Capture when data is entered and multi conditional

    Hello-

    Looking for some assistance to help me write some code to perform the following functions:

    Background: I created a simple userform to enter data into a spreadsheet and now would like to create some reporting from the data that is on the spreadsheet. USERFORM1 writes the information to the the "DETAILS" worksheet.

    Functionality needed:

    1. When there is only a date and time stamp in column (C) "Date and Time Opened", I need it to subtract the date and time in this cell from the current time (=Now()) and put the results in column (K) "Total Hours Open), on that same row. Each time the spreadsheet is opened I want it to refresh the Total Hours Open. Formatting for Date and Time fields are MM/DD/YYYY HH:MM:SS.

    2. When there is a date and time stamp in column (C) "Date and Time Opened" as well as a date and time stamp in column (H) "Date and Time Closed", I need it to perform a function to put the results in column (L) "Total Hours Once Closed".

    3. Once there is a a value in column (L) "Total Hours Once Closed", I need it to multiply column (L) "Total Hours Once Closed" by column (F) "# Employees Affected" and put the results in column (M) "Total Labor Hours Lost by Incident". Formating for this value is HH:MM:SS.

    I am stuck on where this code should reside, in the the USERFORM or the WORKSHEET?

    Any assistance would be greatly appreciated.

    Thanks.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Time/Date Capture when data is entered and multi conditional

    Not sure if you really need code. If you want the calculations to only occur "each time the spreadsheet is opened," then you should put the code in the workbook as a Workbook_Open event.

    However, why not just use formulas?
    1. =if(isnumber(C1),now()-c1,"")
    2. =if(and(isnumber(c1), isnumber(h1)),h1-c1,"")
    Note: if you only want to display hours, then you would use a custom number format of [h] or [h].mm
    3. =if(isnumber(L1), L1*F1,"")
    Custom format as [h].mm.ss
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Registered User
    Join Date
    01-26-2015
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Time/Date Capture when data is entered and multi conditional

    Pauleyb-

    Appreciate the response. I initially started with the formulas, however, the issue that I ran into was when I copied the formula down to the below cells, my userform would see that as being a value and write the new line after all the lines with formulas' ended. Is there another way for me to tell the userform that even though there formulas in those columns to the right that it will still enter the data in?

    Thanks!

  4. #4
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Time/Date Capture when data is entered and multi conditional

    Okay, I think you want to use a Table. You can create one by highlighting a cell in your table and then hitting Ctrl-T. This creates a Table object (aka List pre-2007, I think) that has the nice feature of copying down equations when you add a new row. This means you don't have a lot of unused rows with 'empty' forumlae in them. Play around with it a bit, and you will see what I mean - go to the row just below your Table and add some info - the Table will automatically expand down and will populate the new row with any equations that were in the row above it.
    This will allow you to find the first empty row after your data. Then you can add the data to the bottom row, and when it is added, the table will expand down to include your data, and will copy down any formulas. I think that will work for you. The only caveat is that I remember from VBA, just adding the data below the table will not cause the table to auto-expand. I know I solved a problem like that in the past, but I can't quite find it. I think this thread may have a key part of it, though, by using the .Add method to a table. I think that does it. If not, let me know and I can dig deeper (although I think I used 'Record Macro' to see how to do it in VBA).
    Alternatively, your user form can decide which column to look at for the last 'real' line in your data. Is there a column which is populated when there is data, but empty (i.e. no formula) when there is no data? Search that column to find your true new line.

+ 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. Replies: 2
    Last Post: 04-09-2012, 08:21 AM
  2. [SOLVED] Capture and Store the date that data is entered in Excel?
    By Vasant Nanavati in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 09-06-2005, 07:05 PM
  3. [SOLVED] Capture and Store the date that data is entered in Excel?
    By Nicegy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 PM
  4. Capture and Store the date that data is entered in Excel?
    By Nicegy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  5. [SOLVED] Capture and Store the date that data is entered in Excel?
    By Nicegy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  6. Capture and Store the date that data is entered in Excel?
    By Vasant Nanavati in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 07:05 AM
  7. Capture and Store the date that data is entered in Excel?
    By Vasant Nanavati in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 04:05 AM
  8. [SOLVED] Capture and Store the date that data is entered in Excel?
    By Nicegy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 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