Yes. I want to do this with a vba codeWill you be reusing the cell that has the input? If you input time eg 3:30 excel will format that cell to time. Then you cant just type 3.3 in that same cell as it will be converted to a time (actually a time and date but you wont see the date part). If you arent reusing the cells then its possible.
For Each cell In isect
If (Application.IsNumber(cell) = True) Then
If cell.value > 1 then cell = cell / 24
End If
Next cell
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, c As Range
Set rng = Intersect(Target, Columns("A"))
If Not rng Is Nothing Then
If rng.Rows.Count <> Rows.Count Then
For Each c In rng
If IsNumeric(c.Value) Then
If c.Value > 1 And c.Value <> Int(c.Value) Then
c.Value = Int(c.Value) / 24 + Evaluate("MOD(" & c.Value & ",1)") / 0.6 / 24
End If
End If
Next
End If
End If
End Sub
You cant just divide by 24. 3.30 for example is not going to convert to 3:30 if divided by 24.
Try this. It solely based on the number being typed is greater than 1.
Code:Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range, c As Range Set rng = Intersect(Target, Columns("A")) If Not rng Is Nothing Then If rng.Rows.Count <> Rows.Count Then For Each c In rng If IsNumeric(c.Value) Then If c.Value > 1 And c.Value <> Int(c.Value) Then c.Value = Int(c.Value) / 24 + Evaluate("MOD(" & c.Value & ",1)") / 0.6 / 24 End If End If Next End If End If End Sub
Thankful . But for all time there must be a way.It will only work if you're entering time of day with nothing earlier than 01:00 hrs. For duration or times before 01:00 there is no way of doing what you want.Code:For Each cell In isect If (Application.IsNumber(cell) = True) Then If cell.value > 1 then cell = cell / 24 End If Next cell