如果Feed表添加了新行,我有一个宏将记录添加到存储表。 它工作正常,不会产生错误。 但有时会在没有添加新行 的情况下将记录 添加到Feed表中。
我想知道在添加新记录之前我需要添加什么才能始终确认?
代码:
Private Sub Worksheet_Calculate()
Dim n As Long
n = GetTableSize() '**GetTableSize monitors a static cell which calculates table number of used rows in a table. If that number is different than LastRowNumber...**
If n > LastRowNumber Then NewDatabaseEntry **' NewDatabaseEntry adds new records
' Always set LastRowNumber so that even after entries are deleted (n < NumRows),
' adding new entries will work correctly.**
LastRowNumber = n 'It then resets the values so they are equal again
End Sub
有时候,我在fed表中工作,然后我去检查记录表并添加了一组新记录,即使没有添加新行。 有没有办法添加一个消息框,询问您是否要添加新记录,如果单击否,它会阻止它运行吗?
我目前收到以下代码的错误。如果我让它正常工作,这可能是一个解决方案吗?
答案 0 :(得分:0)
编辑:已解决!!
Private Sub Worksheet_Calculate()
Dim n As Long
Dim rspn As VbMsgBoxResult
rspn = MsgBox("Did you want to add a project?", vbYesNo)
If rspn = vbNo Then Exit Sub
'code
n = GetTableSize()
If n > LastRowNumber Then NewDatabaseEntry
' Always set LastRowNumber so that even after entries are deleted (n < NumRows),
' adding new entries will work correctly.
LastRowNumber = n
End Sub