Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default How to extend the life of a variable from one Private Sub routine to another?

2003/2007

How can I keep the Var "OrigRows" available from
Private Sub Worksheet_Activate() thru to
Sub Worksheet_Change(ByVal Target As Range) see below.

If not, how can I best execute the "If" clause only when the
worksheet change event in an add-to-rows?

********************

Private Sub Worksheet_Activate()

OrigRows = Sheets("Trial Balance Current").UsedRange.Rows.Count

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Sheets("Trial Balance Current").Rows.Count OrigRows Then
Dim myRange As Range
ActiveSheet.Unprotect Password:="calldennis"
Set myRange = Intersect(ActiveSheet.UsedRange, Selection)
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Protect Password:="calldennis", DrawingObjects:=False, Contents:=True, _
Scenarios:=False, AllowFormattingCells:=True, AllowFormattingRows:=True, _
AllowInsertingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
End If

***************

TIA EagleOne
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default How to extend the life of a variable from one Private Sub routineto another?

wrote:
2003/2007

How can I keep the Var "OrigRows" available from
Private Sub Worksheet_Activate() thru to
Sub Worksheet_Change(ByVal Target As Range) see below.

If not, how can I best execute the "If" clause only when the
worksheet change event in an add-to-rows?

********************

Private Sub Worksheet_Activate()

OrigRows = Sheets("Trial Balance Current").UsedRange.Rows.Count

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Sheets("Trial Balance Current").Rows.Count OrigRows Then
Dim myRange As Range
ActiveSheet.Unprotect Password:="calldennis"
Set myRange = Intersect(ActiveSheet.UsedRange, Selection)
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Protect Password:="calldennis", DrawingObjects:=False, Contents:=True, _
Scenarios:=False, AllowFormattingCells:=True, AllowFormattingRows:=True, _
AllowInsertingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
End If

***************

TIA EagleOne


I think you might want to declare OrigRows as a global. Also, if you
expect this to remain static through the life of the workbook you will
need to make sure it is not overwritten on each _Activate event. This
can be done with some code in said procedure with a global or static
variable to hold the state of whether OrigRows has been updated.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default How to extend the life of a variable from one Private Sub routine to another?

I think i got your thought, thanks!

smartin wrote:

wrote:
2003/2007

How can I keep the Var "OrigRows" available from
Private Sub Worksheet_Activate() thru to
Sub Worksheet_Change(ByVal Target As Range) see below.

If not, how can I best execute the "If" clause only when the
worksheet change event in an add-to-rows?

********************

Private Sub Worksheet_Activate()

OrigRows = Sheets("Trial Balance Current").UsedRange.Rows.Count

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Sheets("Trial Balance Current").Rows.Count OrigRows Then
Dim myRange As Range
ActiveSheet.Unprotect Password:="calldennis"
Set myRange = Intersect(ActiveSheet.UsedRange, Selection)
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Protect Password:="calldennis", DrawingObjects:=False, Contents:=True, _
Scenarios:=False, AllowFormattingCells:=True, AllowFormattingRows:=True, _
AllowInsertingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
End If

***************

TIA EagleOne


I think you might want to declare OrigRows as a global. Also, if you
expect this to remain static through the life of the workbook you will
need to make sure it is not overwritten on each _Activate event. This
can be done with some code in said procedure with a global or static
variable to hold the state of whether OrigRows has been updated.

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
Call a Private Sub using a variable Caezar Excel Programming 3 May 4th 08 02:47 PM
private variable: same module, other Sub/Function Stefi Excel Programming 4 July 5th 05 09:10 AM
Initialize a Private variable jerry chapman[_2_] Excel Programming 5 February 21st 05 11:41 PM
Life of a variable Mike Fogleman Excel Programming 1 February 20th 04 12:24 PM
Variable life morph Excel Programming 1 December 3rd 03 10:57 PM


All times are GMT +1. The time now is 04:13 PM.

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

About Us

"It's about Microsoft Excel"