+ Reply to Thread
Results 1 to 7 of 7

difference in minutes using vba from text cells in a userform

  1. #1
    Registered User
    Join Date
    03-02-2019
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    difference in minutes using vba from text cells in a userform

    My first post to the forum. Thanks in advance for any help

    I have used excel for some time, but fairly new to VBA.

    I am creating a userform to use as an audit tool at work (my first time doing a form). I want to calculate the time difference in minutes between a patient arriving at hospital and receiving a drug. The result would then be put into a field within the userform. I'm building the form at home with Excel 2007

    I have put the dates and times into separate text boxes and after update set the dates to dd/mm/yyyy and times to hh:mm formats. I have kept the data and time separate to make it easier to fill dates in other parts of the form.

    I can't calculate just off the times as the arrival date and drug given date may not be the same, but drug would always come after arrival.

    Text boxes are called:
    Arrival date = ArrivalDateTxt
    Arrival time = ArrivalTimeTxt
    Drug given date = tPAStartedDateTXT
    Drug given time = tPAStartedTimeTXT
    Result in minutes to go into = tPADTNMinutesTXT


    Cheers
    Steve
    I have tried different things but non have worked, think due to my lack of understanding/experience with VBA

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: difference in minutes using vba from text cells in a userform

    Hi there,

    See if the UserForm in the attached workbook gets you moving in the right direction.

    The UserForm uses the following code:

    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: difference in minutes using vba from text cells in a userform

    or you can try this:
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-02-2019
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: difference in minutes using vba from text cells in a userform

    Hi Greg

    Many thanks for the reply, think I will need to spend a bit of time to work my head around the code.

    One question at the moment though, in the initialize coding what does this code do:
    .btnClose.Cancel = True
    .btnClose.SetFocus

    I can tell it is to do with the close button

    Thanks again
    Steve

  5. #5
    Registered User
    Join Date
    03-02-2019
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: difference in minutes using vba from text cells in a userform

    Hi dmcgov

    Many thanks for the file, I like the way the buttons put in today's date. That I will use as the audit will be done as patients are in our ED.

    I am not understanding the parts in Button5 coding, where you use "If a <10" and "If b < 10". What does the a and b stand for?

    Cheers
    Steve

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: difference in minutes using vba from text cells in a userform

    Hi again,

    Many thanks for your feedback.


    The .btnClose.Cancel = True statement just means that the routine associated with clicking on the Close button will be executed if the ESC key is pressed - I find this provides a quick way of closing the UserForm.

    The .btnClose.SetFocus statement means that the Close button will have the focus (i.e. be "selected") when the UserForm is displayed.


    Feel free to shout if you need any further information.

    Regards,

    Greg M

  7. #7
    Registered User
    Join Date
    03-02-2019
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: difference in minutes using vba from text cells in a userform

    Thanks for the clarification Greg.

    That code makes perfect sense now

    Steve

+ 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. Fin out time difference in hours or minutes
    By ajuto1989 in forum Excel General
    Replies: 2
    Last Post: 02-19-2018, 12:25 PM
  2. Userform compute for time difference in text box
    By aarona in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2017, 01:20 PM
  3. Calculate "hours:minutes" difference between two "dates:times:minutes"
    By Neyme in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-26-2016, 11:03 PM
  4. [SOLVED] Minutes difference between two dates in VBA
    By lostest in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 10-31-2015, 10:02 PM
  5. VBA userform Time difference in text box
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2012, 04:56 AM
  6. Date Difference to minutes.
    By Keen in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-07-2009, 07:06 PM
  7. [SOLVED] Calc minutes and seconds difference
    By Coach in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 05-28-2006, 10:40 AM

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