超出堆栈空间运行时间:1004错误
Private Sub Worksheet_Change(ByVal Target As Range) Worksheets("Order_Form").Cells(39, 2) = Environ("USERNAME") ' Pop up a warning when the user input more than 1000 cases If Target.Column = 7 And (Target.Row < 34 And Target.Row > 13) Then If Cells(Target.Row, Target.Column) > 1000 Then MsgBox "You are ordering more than 1000 cases", vbCritical End If End Sub
这带来了堆栈空间错误(运行时错误1004)
它通常发生在我尝试编辑任何单元格时
任何人有想法为什么?
谢谢!
第一行将使您进入无限循环,因为您正在Worksheet_Change事件内启动工作表更改。 尝试这个:
Private Sub Worksheet_Change(ByVal Target As Range) On Error GoTo err_handler Application.EnableEvents = False Worksheets("Order_Form").Cells(39, 2) = Environ("USERNAME") Application.EnableEvents = True ' Pop up a warning when the user input more than 1000 cases If Target.Column = 7 And (Target.Row < 34 And Target.Row > 13) Then If Cells(Target.Row, Target.Column) > 1000 Then MsgBox "You are ordering more than 1000 cases", vbCritical End If err_handler: Application.EnableEvents = True End Sub
看看这篇文章。 它说,如果你的数组中的一个单元格有超过911个字符(什么是随机数),它是一个常见的问题。 而且我看到你的最多可以容纳1000个。这个链接包含了一个可以帮助你的工作。 干杯!