精通excel VBA的高手请进,同样的代码,为什么EXCEL2013会停止工作,在EXCEL2007里正常!!!

如题图片所示,选择任意一行数据在 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

你的代码较多,很难一句一句分析,你自己分步执行看到了哪句死的,才好分析。前不久我也遇到你一样的情况,并且代码还是通过录制宏来改的,很简单的复制工作表的语句,高版本运行正常。找不到原因,再反过来运行录制的宏,居然也死了,最后在sheet的前面加上工作簿thisworkbook.才解决问题。
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网