Solved

TIme format

Posted on 2014-09-15
4
107 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 32

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

21 Experts available now in Live!

Get 1:1 Help Now