0
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)

它通常发生在我尝试编辑任何单元格时

任何人有想法为什么?

谢谢!

4

2 回答 2

2

The first line is putting you into an endless loop, as you are initiating a worksheet change inside the Worksheet_Change event. Try this:

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
于 2013-08-01T15:57:33.080 回答
0

看看这篇文章。如果您的数组中的一个单元格有超过 911 个字符(多么随机数),它表示这是一个常见问题。而且我看到您的最多可以包含 1000 个。该链接包含一个解决方法,希望可以帮助您。干杯!

http://support.microsoft.com/kb/818808

于 2013-08-01T15:55:21.583 回答