【发布时间】:2022-01-27 13:24:38
【问题描述】:
我正在尝试在用户输入后自动向单元格值添加破折号,但每次我测试代码时,我的 excel 都会在显示错误后重新启动。这段代码有什么问题?
我想要实现的是在每 3 个字符后插入破折号
abc123abcde =abc-123-abc-de
Private Sub Worksheet_Change(ByVal Target As Range)
If Selection.Count > 1 Then
Exit Sub
End If
If Not Intersect(Range("a2:a100"), Target) Is Nothing Then
DLen = Len(Target)
If DLen < 10 Then
Target = Left(Target, 2) & "-" & Right(Target, 4)
ElseIf DLen > 10 Then
'do nothing
MsgBox "more 10"
End If
Target.NumberFormat = "@"
Application.EnableEvents = False
Target = DateV
Application.EnableEvents = True
End If
End Sub
【问题讨论】:
-
Target = Left(...应该是DateV = Left(...