
我在用Excel 2013創建一個將由最終用戶填充的工作簿,老實說,我有很多驗證,因此當用戶嘗試貼上超過 2000 行時,需要花費很多時間。
我的問題不在於性能,我只是想message box
在用戶嘗試貼上超過2000行。我在谷歌中查找了它,但找不到有關它的資訊。
答案1
答案2
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sLastOp As String
Dim cell As Range
Dim a As Integer
Dim Row As Range
a = 0
For Each Row In Range(Target.Cells.Address)
If InStr(Row.Address, "A") Then
a = a + 1
End If
Next
'--get the last operation from the undo stack
sLastOp = Application.CommandBars("Standard").FindControl(ID:=128).List(1)
Select Case sLastOp
'--if last operation was Paste or PasteSpecial, display message
Case "Paste", "Paste Special"
If a > 200 Then MsgBox "Please wait till pasting finishes." & a, vbOKOnly
Case Else 'do nothing
End Select
End Sub
將此程式碼放入新的工作表中,貼上時將 100% 有效,您可以根據需要修改訊息。
但老實說,如果您嘗試刪除超過 2000 行,則會出現錯誤。
另一個問題是我無法將此程式碼放入我的工作表程式碼中,我不知道它不起作用的問題是什麼。