Results 1 to 10 of 16

Thread: Timespan Starting With Active Cell Value Using Input Box Value

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0
    Thank you for the direction and solution. I did several tests with the adjusted code and it worked like the original. Thank you


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 06-11-2023 at 03:29 PM.

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by Smd747 View Post
    Thank you for the direction and solution. I did several tests with the adjusted code and it worked like the original. Thank you
    Just to follow up...

    Admin's solution does not actually work like you intended your original code to... in your original code, you were able to select the cell that contained the date if your active cell was not the correct one, Admin's solution would have you typing the date in under that circumstance. The following method would default the InputBox to the active cell's address, but would allow you to select a different cell if the active cell was not on the correct date to begin with (no typing required)...

    Set Cel = Application.InputBox(Prompt, Title, ActiveCell.Address, , , , , 8)


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 06-11-2023 at 03:32 PM.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0
    In hind site, Ideally what I would like is when iI click the macro button that activates the code it prompts me for the ending time because the start time was automatically captured as being the active cell. with this code. Mod it confirms the active cell time is correct but I still have to click ok to get the prompt for the ending time
    The above will save me a click

    I'm think that at the end you get a message box that shows what the start was, what the ending time was and the break time deducted. And of course what the answer the is as a complete check

    Do not know if this is possible

    Still testing your suggestion will post test results later

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by Smd747 View Post
    In hind site, Ideally what I would like is when iI click the macro button that activates the code it prompts me for the ending time because the start time was automatically captured as being the active cell. with this code. Mod it confirms the active cell time is correct but I still have to click ok to get the prompt for the ending time
    The above will save me a click

    I'm think that at the end you get a message box that shows what the start was, what the ending time was and the break time deducted. And of course what the answer the is as a complete check
    Something like this maybe...
    Code:
    Sub GetStartEndTime()
      Dim StartTime As Date, EndTime As Date, TimeDiff As String
      StartTime = ActiveCell.Value
      EndTime = Application.InputBox("Select the cell with the ending time...", Type:=8)
      TimeDiff = Format(EndTime - StartTime, "h"" hours and ""m"" minutes""")
      MsgBox "Start time: " & StartTime & vbLf & "End time: " & EndTime & vbLf & "Time difference: " & TimeDiff
    End Sub

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0
    Your mod works very well, I like the hours and minutes to the value, thats really cool. Is it possible to add the break value to this code to say minus 60 minutes the value of the input which is either 30 or 60 ? this way I don't have to mentally deduct it from the times to get the value. Thanks you for the help and direction

  6. #6
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by Smd747 View Post
    Your mod works very well, I like the hours and minutes to the value, thats really cool. Is it possible to add the break value to this code to say minus 60 minutes the value of the input which is either 30 or 60 ? this way I don't have to mentally deduct it from the times to get the value. Thanks you for the help and direction
    I don't understand the part I highlighted in red... what is to be subtracted 30 or 60 and how is the code supposed to know which? Please give me an example and show me what the message box should say for the time difference for that example.

  7. #7
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0
    How could I hard code 60 which is 60 minutes lunch break or 1-hour
    Code:
    TimeDiff = Format(EndTime - StartTime, "h"" hours and ""m"" minutes""") - 60
    did not work. I'm thinking I can have two buttons one for a 60 minute lunch break or 30 minute lunch break break to be deducted at the end. I hope I explained it better, sorry

Similar Threads

  1. Highlight Active Cell’s Row and Column
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 05-17-2013, 12:32 AM
  2. Replies: 8
    Last Post: 04-16-2013, 02:04 PM
  3. List of Dates In DropDown Starting From Today()
    By rich_cirillo in forum Excel Help
    Replies: 5
    Last Post: 04-10-2013, 05:58 PM
  4. How to Lock or Unlock row basis previous cell input?
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 2
    Last Post: 07-25-2012, 02:40 PM
  5. Sample VB programs for Starting VB
    By sumit.dutt in forum Excel Help
    Replies: 2
    Last Post: 12-27-2011, 07:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •