自动格式化比赛结果时间

我已经开始创build一个VBAmacros,帮助我添加格式到行,因为我添加了一个自定义的NumberFormat。 但是因为我的合作伙伴和我有时input像“ss.00”的项目,这个搞砸了单元格。 于是我开始写另外一个Sub,检查它是否丢失了分号。 在单元格显示“0:50.20”的地方,我怎样才能在这个值的前面加上“0:”,每次我这样做,最后都是一个很长的数字。

Private Sub Worksheet_Change(ByVal Target As Excel.Range) If Target.Cells.Count = 1 Then If Target.Column = 1 Then If Target.Row < 24 And Target.Row > 1 Then Set FirstRow = Target.Offset(0, 1) Set LastRow = Target.Offset(0, 11) If Target.Value <> "" Then For Each Cel In Range(FirstRow, LastRow) Cel.NumberFormat = "m:ss.00;@" Next Else If MsgBox("This will erase the row! Are you sure?", vbYesNo) = vbNo Then Exit Sub Else For Each Cel In Range(FirstRow, LastRow) Cel.ClearContents Next End If End If End If End If Const sCheckAddress As String = "B2:L24" Dim rngIntersect As Range On Error Resume Next Set rngIntersect = Intersect(Me.Range(sCheckAddress), Target) On Error GoTo 0 If Not (rngIntersect Is Nothing) Then If Target.Value2 <> "" Then If InStr(Target.Value2, ":") < 1 Then End If End If End If End If End Sub 

也许这会帮助你:

 If InStr(Target.Value2, ":") < 1 Then ' ":" not found Target.Value = CStr("0:" & Target.Value) Else ' ":" found 'Nothing to add End If