+ Reply to Thread
Results 1 to 5 of 5

Entering time using decimal place or Colon

Hybrid View

  1. #1
    Registered User
    Join Date
    02-07-2012
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Entering time using decimal place or Colon

    Hi folks,

    I did a search on here and found some code that does what i want (mostly) which is to allow users to enter a time in either 7.3 or 7:30 and have it display as 7:30. Except it doesn't work if some one enters a time less than 1 for expamle enters 0.3 (meaning 0:30) it shows 7:12
    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "C4:V23"
    
    On Error GoTo ws_exit:
    Application.EnableEvents = False
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    If IsNumeric(.Value) And .Value >= 1 Then
    .Value = (Int(.Value) + (.Value - Int(.Value)) * 100 / 60) / 24
    .NumberFormat = "[h]:mm"
    End If
    End With
    End If
    
    ws_exit:
    Application.EnableEvents = TrueEnd Sub
    I have tried changing the code
    If IsNumeric(.Value) And .Value >= 1 Then
    to
    If IsNumeric(.Value) And .Value >= 0 Then
    but then it will not acept time entered with a colon.

    Can anyone help me, what do i need to change?

    I'm using excel 2003

    Thanks, Mira.
    Last edited by Mira Sheridan; 02-08-2012 at 07:35 AM. Reason: add details of excel version

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Entering time using decimal place or Colon

    That look suspiciously like my old code.

    Anyway
    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "C4:V23"
        
        On Error GoTo ws_exit:
        Application.EnableEvents = False
    
        If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
        
            With Target
            
                If IsNumeric(.Value) And .Value >= 0 Then
                
                    .Value = (Int(.Value) + (.Value - Int(.Value)) * 100 / 60) / 24
                    .NumberFormat = "[h]:mm"
                End If
            End With
        End If
        
    ws_exit:
        Application.EnableEvents = True
    End Sub

  3. #3
    Registered User
    Join Date
    02-07-2012
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Entering time using decimal place or Colon

    Quote Originally Posted by Bob Phillips View Post
    That look suspiciously like my old code.

    That cos it was your code i found

    That fixes the 0.3 problem but now if you try and enter 1:00 it changes it to 0:04 instead of leaving it as 1:00

    Any sugestions?

    Thanks, Mira.

  4. #4
    Registered User
    Join Date
    02-07-2012
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Entering time using decimal place or Colon

    I forgot to say I know nothing about VBA so I am unable to diagnose the problem my self.
    Any help is much appreciated

    Mira.

  5. #5
    Registered User
    Join Date
    02-07-2012
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Entering time using decimal place or Colon

    Bump.
    I'm still searching for an answer to my problem
    Any help much apprectiated and maybe even see my way clear to paypal'ing a few beer tokens to the person who can solve my problem

    Thanks, Mira.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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