Unexpected Value Returned on Count

theteerex

Board Regular
Joined
Mar 2, 2018
Messages
102
Code:
Public NumRows As Long
The number of used rows on Worskheet 1. Variable is public because multiple macros use it.
Code:
Private Sub Workbook_Open()
  NumRows = Worksheets("TableSize").Range("A1").Value
  MsgBox "NumRows = " & NumRows
End Sub
Calculates the value of the variable NumRows, which is the number of rows used on Sheet 1. MsgBox was inserted simply to verify code was working.
Sheet TableSize only has information in A1.
Code:
Private Sub Worksheet_Calculate()


    Dim n As Long
    n = Worksheets("TableSize").Range("A1").Value [B][COLOR=#008000]'A1 contains the formula "=ROW(INDEX(Sheet1,1,1))+ROWS(Sheet1)-1" used to count rows on Sheet 1[/COLOR][/B]
    MsgBox n & "NumRows=" & NumRows [B][COLOR=#ff0000]'For some reason NumRows returns 0 here when it returns 32 above. n returns 32 like it should[/COLOR][/B]
    If n = NumRows Then Exit Sub
    If n > NumRows Then Call NewDatabaseEntry
    
    NumRows = n


End Sub

Am I missing something crucial?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Where have you put this
Code:
Public NumRows As Long
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top