Solved

TIme format

Posted on 2014-09-15
4
112 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 33

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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