My code is supposed to run only if n > NumRows.
n is the number of rows in my worksheet. I calculate the number using a formula in another spreadsheet at location A1.
For the purposes of this post, that number is 30.
My code:
The problem is, whenever I run ANY macro on the worksheet that can have rows added, my MacroY runs, adding more rows to a 3rd worksheet.
Am I missing something? To me, the code looks like it is telling MacroY to run only if n > NumRows. Am I wrong?
Is it the _Calculate?
Any help would be awesome!
n is the number of rows in my worksheet. I calculate the number using a formula in another spreadsheet at location A1.
For the purposes of this post, that number is 30.
My code:
Code:
'Sheet where row number is calculated, 30 for this example
Private Sub Worksheet_Calculate()
Dim n As Long
n = Worksheets("TableSize").Range("A1").Value
If n > NumRows Then Call MacroY 'MacroY is a sub that is called if there is an increase in rows, leading to a difference between n and NumRows
NumRows = n
End Sub
Code:
Public NumRows As Long
Code:
'Located in the worksheet where rows are added. Currently at 30 rows as well
Private Sub Workbook_Open()
NumRows = Worksheets("TableSize").Range("A1").Value
End Sub
The problem is, whenever I run ANY macro on the worksheet that can have rows added, my MacroY runs, adding more rows to a 3rd worksheet.
Am I missing something? To me, the code looks like it is telling MacroY to run only if n > NumRows. Am I wrong?
Is it the _Calculate?
Any help would be awesome!