Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

Enter military time in Excel without ":"

$
0
0

I'm using this script I found on the Microsoft forum to allow me to enter military time without having to enter the ":" every time. It works fine, until I add a blank row or delete a row. Then I get an error. How can I get this code to ignore deletions and additions in the range that don't meet the expected format?

 Private Sub Worksheet_Change(ByVal Target As Range)
 If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
 Dim xHour As String
 Dim xMinute As String
 Dim xWord As String
 Application.EnableEvents = False
 xWord = Format(Target.Value, "0000")
 xHour = Left(xWord, 2)
 xMinute = Right(xWord, 2)
 On Error Resume Next
 Target.Value = TimeValue(xHour & ":"& xMinute)
 On Error Resume Next
 Application.EnableEvents = True
 End Sub

Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>