Solved

TIme format

Posted on 2014-09-15
4
106 Views
Last Modified: 2014-09-16
I have a spreadsheet that has cel formatted [hh]:mm if the user enters a "." instead of a ":" the cell formatting is not correct how tyot i replace the period Example 6.00 should be 06:00.see the attached file.

Thanks
Book1times.xlsm
0
Comment
Question by:Svgmassive
4 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 500 total points
ID: 40324135
Hi,

Would this be suitable for you?

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

  Select Case (True)
  
      Case (Intersect([I17:N17], Target) Is Nothing)
      
      Case (Not (IsNumeric(Target)))
      
      Case (Val(Target) > 1)
          Application.EnableEvents = False
          
          If InStr(CStr(Target), ".") > 0 Then
             Target = Format(Replace(CStr(Target), ".", ":"), "HH:MM")
          Else
             Target = Format(Replace(CStr(Target) & ".00", ".", ":"), "HH:MM")
          End If
          
          Application.EnableEvents = True
      
      Case Else
      
  End Select
  
End Sub

Open in new window


Please (also) see the attached workbook.
Q-28518882.xlsm
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40324253
You could set up Data Validation on these cells to limit entry between 0 and 1 (days, implicit).  That would prevent anyone from entering 6 days as a value.  

You could further enforce this by calculating the fraction of a day that the maximum number of allowable hours is.  If 8 hours is the maximum, the data validation limit would be 0.33333.  If 12 hours, then 0.5.

See the attached example workbook with data validation added.

Regards,
-Glenn
EE-Book1times.xlsx
0
 
LVL 31

Expert Comment

by:Rob Henson
ID: 40325025
Alternatively, you can set Data Validation to only accept a Time value. With this you can set a Earliest and Latest time.

However, if you are entering a length of time (rather than a clock time) and the time entered is greater than 24 Hours, the DV won't accept it.

Thanks
Rob H
0
 

Author Closing Comment

by:Svgmassive
ID: 40325109
Wonderful exactly what i needed.Thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now