My code is supposed to be a simple table length check.
If the table length increases, a macro runs.
Unfortunately, it runs when I modify any data in an existing record. But it only happens once!
It occurs when I open the workbook initially and then try to modify anything in the workbook. After which, it runs as it should, only when you added a new entry.
Sub is located on the worksheet that contains static cell A1. This is the problem macro. It seems to behave as if there is a difference between the number of rows and the static range. But again, only when you initially open the workbook!
Private Sub Worksheet_Calculate()
Dim n As Long
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
Supporting macro in a separate module:
Option Explicit
Public LastRowNumber As Long
'This will be used to monitor the number of rows in the
'Projects worksheet. This will then be compared to the
'Value of the formula in the TableSize worksheet.
'The value in TableSize will have a variable 'n'.
Public Function GetTableSize() As Long
GetTableSize = Worksheets("TableSize").Range("A1").Value2
End Function
This sub is located on the worksheet where the table being monitored resides:
Private Sub Workbook_Open()
LastRowNumber = GetTableSize()
End Sub
NewDatabaseEntry is the module that alerted me to the fact that there was a problem as it shows a pop-up before it runs. Otherwise, I would've been unaware of there being a problem in the first place.
Any help would be appreciated.
Value2? Is there some purpose?