K
kimc
Is there a way to set up a cell so that I can type in 1330, and have Excel put in the colon so it reads 13:30 (military time)?
put in the colon so it reads 13:30 (military time)?kimc said:Is there a way to set up a cell so that I can type in 1330, and have Excel
Don Guillett said:right click sheet tab>view code>insert this. As written, works on a1:a100
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range) 'Ron Rosenfeld
<[email protected]>
Dim InputRange As Range
Dim Temp As Variant
Dim i As Integer
Dim Separators(2) As String
Separators(0) = ";"
Separators(1) = ","
Separators(2) = "."
Application.EnableEvents = False
Set InputRange = [A1:A100] 'or whatever
If Intersect(Target, InputRange) Is Nothing Then GoTo Bye
If Target.Value = 0 Then GoTo Bye
Temp = Target.Value
'If entry is an integer, then make it a time
On Error GoTo ConvertString
If Int(Temp) = Temp Then
Temp = (Int(Temp / 100) + (Temp / 100 - Int(Temp / 100)) * 100 / 60) /
24
GoTo Last
ElseIf Temp < 1 Then 'probably a time
GoTo Last
End If
If Temp > 15000 Then 'probably a date/time string
Temp = CDate(Temp - Int(Temp))
GoTo Last
End If
ConvertString: 'replace separator with colon unless the string is a
date
On Error GoTo 0
For i = 0 To 2
Temp = Replace(Temp, Separators(i), ":")
Next i
Last:
Target.Value = Temp
Target.NumberFormat = "hh:mm"
Bye: Application.EnableEvents = True
End Sub
--
Don Guillett
SalesAid Software
[email protected]
put in the colon so it reads 13:30 (military time)?kimc said:Is there a way to set up a cell so that I can type in 1330, and have Excel
Column A now. Can you just explain this function to me in English?kimc said:Thank you so much! One more question, this is the way my client formats
=LOOKUP(9.99999999999999E+307,A:A)
Don Guillett said:right click sheet tab>view code>insert this. As written, works on a1:a100
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range) 'Ron Rosenfeld
<[email protected]>
Dim InputRange As Range
Dim Temp As Variant
Dim i As Integer
Dim Separators(2) As String
Separators(0) = ";"
Separators(1) = ","
Separators(2) = "."
Application.EnableEvents = False
Set InputRange = [A1:A100] 'or whatever
If Intersect(Target, InputRange) Is Nothing Then GoTo Bye
If Target.Value = 0 Then GoTo Bye
Temp = Target.Value
'If entry is an integer, then make it a time
On Error GoTo ConvertString
If Int(Temp) = Temp Then
Temp = (Int(Temp / 100) + (Temp / 100 - Int(Temp / 100)) * 100 / 60) /
24
GoTo Last
ElseIf Temp < 1 Then 'probably a time
GoTo Last
End If
If Temp > 15000 Then 'probably a date/time string
Temp = CDate(Temp - Int(Temp))
GoTo Last
End If
ConvertString: 'replace separator with colon unless the string is a
date
On Error GoTo 0
For i = 0 To 2
Temp = Replace(Temp, Separators(i), ":")
Next i
Last:
Target.Value = Temp
Target.NumberFormat = "hh:mm"
Bye: Application.EnableEvents = True
End Sub
--
Don Guillett
SalesAid Software
[email protected]
Excelkimc said:Is there a way to set up a cell so that I can type in 1330, and have
put in the colon so it reads 13:30 (military time)?
Don Guillett said:right click sheet tab>view code>insert this. As written, works on a1:a100
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range) 'Ron Rosenfeld
<[email protected]>
Dim InputRange As Range
Dim Temp As Variant
Dim i As Integer
Dim Separators(2) As String
Separators(0) = ";"
Separators(1) = ","
Separators(2) = "."
Application.EnableEvents = False
Set InputRange = [A1:A100] 'or whatever
If Intersect(Target, InputRange) Is Nothing Then GoTo Bye
If Target.Value = 0 Then GoTo Bye
Temp = Target.Value
'If entry is an integer, then make it a time
On Error GoTo ConvertString
If Int(Temp) = Temp Then
Temp = (Int(Temp / 100) + (Temp / 100 - Int(Temp / 100)) * 100 / 60) /
24
GoTo Last
ElseIf Temp < 1 Then 'probably a time
GoTo Last
End If
If Temp > 15000 Then 'probably a date/time string
Temp = CDate(Temp - Int(Temp))
GoTo Last
End If
ConvertString: 'replace separator with colon unless the string is a
date
On Error GoTo 0
For i = 0 To 2
Temp = Replace(Temp, Separators(i), ":")
Next i
Last:
Target.Value = Temp
Target.NumberFormat = "hh:mm"
Bye: Application.EnableEvents = True
End Sub
--
Don Guillett
SalesAid Software
[email protected]
put in the colon so it reads 13:30 (military time)?kimc said:Is there a way to set up a cell so that I can type in 1330, and have Excel
Don Guillett said:right click sheet tab>view code>insert this. As written, works on a1:a100
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range) 'Ron Rosenfeld
<[email protected]>
Dim InputRange As Range
Dim Temp As Variant
Dim i As Integer
Dim Separators(2) As String
Separators(0) = ";"
Separators(1) = ","
Separators(2) = "."
Application.EnableEvents = False
Set InputRange = [A1:A100] 'or whatever
If Intersect(Target, InputRange) Is Nothing Then GoTo Bye
If Target.Value = 0 Then GoTo Bye
Temp = Target.Value
'If entry is an integer, then make it a time
On Error GoTo ConvertString
If Int(Temp) = Temp Then
Temp = (Int(Temp / 100) + (Temp / 100 - Int(Temp / 100)) * 100 / 60) /
24
GoTo Last
ElseIf Temp < 1 Then 'probably a time
GoTo Last
End If
If Temp > 15000 Then 'probably a date/time string
Temp = CDate(Temp - Int(Temp))
GoTo Last
End If
ConvertString: 'replace separator with colon unless the string is a
date
On Error GoTo 0
For i = 0 To 2
Temp = Replace(Temp, Separators(i), ":")
Next i
Last:
Target.Value = Temp
Target.NumberFormat = "hh:mm"
Bye: Application.EnableEvents = True
End Sub
--
Don Guillett
SalesAid Software
[email protected]
put in the colon so it reads 13:30 (military time)?kimc said:Is there a way to set up a cell so that I can type in 1330, and have Excel