啟用宏,并ThisWorkBook中加入如下代碼。(假設)A列輸入12:08——15:25這種,B列輸入:泵送罐送,如果不是,請將下面代碼對應的"A"及"B"改成對應的列代號。
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Mid(Target.Address, 2, InStr(Mid(Target.Address, 2), "$") - 1) = "B" Then
Application.EnableEvents = False
Application.ScreenUpdating = False
If Target.Value = "0" Then
Target.Value = "泵送"
ElseIf Target.Value = "1" Then
Target.Value = "罐送"
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
ElseIf Mid(Target.Address, 2, InStr(Mid(Target.Address, 2), "$") - 1) = "A" Then
If Len(Target.Value) = 8 Then
If Val(Target.Value) > 999999 And Val(Target.Value) < 24000000 Then
Application.EnableEvents = False
Application.ScreenUpdating = False
If Mid(Target.Value, 1, 2) < 24 And Mid(Target.Value, 3, 2) < 60 And Mid(Target.Value, 5, 2) < 13 And Mid(Target.Value, 7, 2) < 60 Then
Target.Value = Mid(Target.Value, 1, 2) & ":" & Mid(Target.Value, 3, 2) & "-" & Mid(Target.Value, 5, 2) & ":" & Mid(Target.Value, 7, 2)
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
ElseIf Len(Target.Value) = 7 Then
If Val(Target.Value) > 999999 And Val(Target.Value) < 9592359 Then
Application.EnableEvents = False
Application.ScreenUpdating = False
If Mid(Target.Value, 1, 1) < 10 And Mid(Target.Value, 2, 2) < 60 And Mid(Target.Value, 4, 2) < 13 And Mid(Target.Value, 6, 2) < 60 Then
Target.Value = Mid(Target.Value, 1, 1) & ":" & Mid(Target.Value, 2, 2) & "-" & Mid(Target.Value, 4, 2) & ":" & Mid(Target.Value, 6, 2)
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End If
End If
End Sub