精通excel VBA的高手请进,同样的代码,为什么EXCEL2013会停止工作,在EXCEL2007里正常!!!
如题图片所示,选择任意一行数据在sum合计行插入复制的数据,excel2013出现偶然性的停止工作现象,未保存的东西都会丢失但是在excel2007里都正常!!!Priv...
如题图片所示,选择任意一行数据在 sum合计行 插入复制的数据,excel2013出现偶然性的停止工作现象,未保存的东西都会丢失 但是在excel2007里都正常!!!
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim Rng As Range, R As Range, Tmp$
Set Rng = Intersect(Target, Columns(2))
If Not Rng Is Nothing Then
Application.EnableEvents = False
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "[\u4e00-\u9fa5]"
For Each R In Rng
If Len(R.Text) Then
temp = .Replace(R.Text, "")
If IsError(Evaluate(temp)) = False Then R.Offset(, 1).Value = Evaluate(temp)
Else
If R.Offset(, 3).Value <> "合计" Then R.Offset(, 1).Value = ""
End If
Next R
End With
Application.EnableEvents = True
End If
Set Rng = Nothing
Set R = Nothing
If Target.Column = 3 Then
Application.EnableEvents = False
Set Rng = Columns("C:C").SpecialCells(xlCellTypeFormulas, 23)
Rng.Offset(, 2) = "合计"
If Intersect(Rng, Target) Is Nothing And Target.Offset(, 2) = "合计" Then Target.Offset(, 2) = ""
Application.EnableEvents = True
End If
End Sub 展开
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim Rng As Range, R As Range, Tmp$
Set Rng = Intersect(Target, Columns(2))
If Not Rng Is Nothing Then
Application.EnableEvents = False
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "[\u4e00-\u9fa5]"
For Each R In Rng
If Len(R.Text) Then
temp = .Replace(R.Text, "")
If IsError(Evaluate(temp)) = False Then R.Offset(, 1).Value = Evaluate(temp)
Else
If R.Offset(, 3).Value <> "合计" Then R.Offset(, 1).Value = ""
End If
Next R
End With
Application.EnableEvents = True
End If
Set Rng = Nothing
Set R = Nothing
If Target.Column = 3 Then
Application.EnableEvents = False
Set Rng = Columns("C:C").SpecialCells(xlCellTypeFormulas, 23)
Rng.Offset(, 2) = "合计"
If Intersect(Rng, Target) Is Nothing And Target.Offset(, 2) = "合计" Then Target.Offset(, 2) = ""
Application.EnableEvents = True
End If
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询