Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Public variable not storing

I set the number of rows on opening a file but when I detect a change in a
sheet, the number of rows is empty. Help please!

The code for ThisWorkbook:
Public NrowsSt As Integer
Private Sub Workbook_Open()
NrowsSt = Range("MyRange").Rows.Count
MsgBox NrowsSt
End Sub


The code for Sheet1:

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox NrowsSt
Nrows = Range("MyRange").Rows.Count
If Nrows < NrowsSt Then
If Nrows NrowsSt Then
MsgBox "No of rows inserted =" & Nrows - NrowsSt
Else
MsgBox "No of rows deleted =" & NrowsSt - Nrows
End If
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Public variable not storing

You have declared NRowsSt in ThisWorkbook code module, therefore when
referencing it you need to qualify with the calls module name, i,e,

If NRows ThisWorkbook.NRowsSt

By not doing so,VBA is implicitly declaring a new public variable called
NRowSt, which is obviously empty as you do not load it.

You should have Option Explicit at the head of your code, this would
highlight such problems.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Gleam" wrote in message
...
I set the number of rows on opening a file but when I detect a change in a
sheet, the number of rows is empty. Help please!

The code for ThisWorkbook:
Public NrowsSt As Integer
Private Sub Workbook_Open()
NrowsSt = Range("MyRange").Rows.Count
MsgBox NrowsSt
End Sub


The code for Sheet1:

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox NrowsSt
Nrows = Range("MyRange").Rows.Count
If Nrows < NrowsSt Then
If Nrows NrowsSt Then
MsgBox "No of rows inserted =" & Nrows - NrowsSt
Else
MsgBox "No of rows deleted =" & NrowsSt - Nrows
End If
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Public variable not storing

Found the answer via a Chip Pearson posting on Google Groups:

ThisWorkbook.NrowsSt is needed on the worksheet.

Thank you Chip Pearson.

"Gleam" wrote:

I set the number of rows on opening a file but when I detect a change in a
sheet, the number of rows is empty. Help please!

The code for ThisWorkbook:
Public NrowsSt As Integer
Private Sub Workbook_Open()
NrowsSt = Range("MyRange").Rows.Count
MsgBox NrowsSt
End Sub


The code for Sheet1:

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox NrowsSt
Nrows = Range("MyRange").Rows.Count
If Nrows < NrowsSt Then
If Nrows NrowsSt Then
MsgBox "No of rows inserted =" & Nrows - NrowsSt
Else
MsgBox "No of rows deleted =" & NrowsSt - Nrows
End If
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Public variable not storing

Read my post. There is more info there.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Gleam" wrote in message
...
Found the answer via a Chip Pearson posting on Google Groups:

ThisWorkbook.NrowsSt is needed on the worksheet.

Thank you Chip Pearson.

"Gleam" wrote:

I set the number of rows on opening a file but when I detect a change in
a
sheet, the number of rows is empty. Help please!

The code for ThisWorkbook:
Public NrowsSt As Integer
Private Sub Workbook_Open()
NrowsSt = Range("MyRange").Rows.Count
MsgBox NrowsSt
End Sub


The code for Sheet1:

Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox NrowsSt
Nrows = Range("MyRange").Rows.Count
If Nrows < NrowsSt Then
If Nrows NrowsSt Then
MsgBox "No of rows inserted =" & Nrows - NrowsSt
Else
MsgBox "No of rows deleted =" & NrowsSt - Nrows
End If
End If
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing a value to variable CLamar Excel Discussion (Misc queries) 0 June 16th 06 04:46 PM
Storing variable in Option.Tag augustus Excel Programming 0 February 4th 05 02:45 AM
Storing a range in a variable Mick[_8_] Excel Programming 6 January 15th 05 09:36 PM
Storing value in a variable from a cell Saadi Excel Programming 6 January 8th 05 01:27 PM


All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"