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)
通常在我尝试编辑任何单元格时发生
任何人都有想法的原因?
谢谢!
答案 0 :(得分:2)
第一行是让您进入无限循环,因为您在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
答案 1 :(得分:0)
查看这篇文章。它说如果你的数组中的一个单元格有超过911个字符(一个随机数),这是一个常见的问题。我看到你的最多可以包含1000个。该链接包含一个可以帮助你的工作。干杯!