LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Worksheet_Calculate code in same module as Worksheet Change eventgoes astray

You're right, I don't really know what proper terms to call things. I'll
insert the code here.

On the Project Explorer both the procedures below (Worksheet_Change, and
Worksheet_Calculate) are in the Sheet 5 (Categories) Object. The bottom
one (Worksheet_Calculate) is the problem one. I've set a trap to stop
it on the /"If Cells(5, 2) = 1 Then MsgBox "Fires ok"/" line, then I F8
step thru it. When it finishes the End Sub, it jumps to the top of this
Worksheet_Change code and starts going thru it. So I'm trying to get it
to work properly, then build code around it, ultimately so if it equals
1, then unhide some rows. Thanks again for your kind help. Harold

Private Sub Worksheet_Change(ByVal Target As Range)
'Code below catches any changes made to the green
'table on the Categories page. When any change is made
'the code is triggered and it hides the unused rows of the
'budget on the Budget page.
Dim r As Range, cell As Range
Set t = Target
ActiveSheet.Unprotect Password:="budg"
Range("E10:N29").Interior.Color = RGB(213, 255, 215)
Range("F10").Interior.Color = RGB(255, 255, 189)
Range("E10:N29").Locked = False
Range("F10").Locked = True
If Not Intersect(t, Range("E10:N29")) Is Nothing Then
Dim rngEval As Range
Dim rngHide As Range
Dim rngCell As Range
Set rngEval = Sheets("Budget").Range("BudgetRowsForHiding")
Application.ScreenUpdating = False
For Each rngCell In rngEval.Cells
If rngCell.Value = "" Then
If rngHide Is Nothing Then
Set rngHide = rngCell
Debug.Print rngHide.Address

Else
Set rngHide = Union(rngHide, rngCell)
Debug.Print rngHide.Address

End If
End If
Next rngCell

'Debug.Print rngHide.Address
rngEval.RowHeight = 12.75
Sheets("Budget").Outline.ShowLevels RowLevels:=1
'Because Hidden rows do not remain hidden on the Budget page when I
'expand the Outline, the only other way to make unused rows remain
'hidden is to use a rowheight of .6. This keeps these unused rows
'out of sight while keeping them also out of sight when expanding
'the Outline on Budget page.
Sheets("Budget").Unprotect Password:="budg"

'If there are 30 Account Categories, then don't do the rngHide below.
If rngHide Is Nothing Then
Else
rngHide.RowHeight = 0.6
End If

End If
Sheets("Budget").Shapes("Group Charts").Visible = True
Sheet1.Select
Sheet1.Range("NotesRows").Select
Selection.EntireRow.Hidden = False
Sheets("Budget").Range("H7").Select
Sheet5.Select
Sheets("Budget").Protect Password:="budg"
Application.ScreenUpdating = True
Application.EnableEvents = True
'ActiveSheet.Protect Password:="budg"
End Sub

Private Sub Worksheet_Calculate()
Application.EnableEvents = False
If Cells(5, 2) = 1 Then MsgBox "Fires ok"
Application.EnableEvents = True
End Sub



Rick Rothstein wrote:
What do you mean "entered as a separate procedure below the
Worksheet_Change procedure"? You have to incorporate my posted code
into your existing Worksheet_Change procedure's code... where might
depend on when you need it to execute relative to the other code you
have. Without seeing the rest of your code, it is kind of hard to give
you any more direction than this.



 
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
Change A Line in A Module Using VBA Code derrick Excel Programming 1 July 3rd 08 02:01 PM
Code to change code in a sheet and workbook module Otto Moehrbach Excel Programming 11 November 11th 07 07:20 PM
Pass variables from Worksheet_Calculate sub to Module John Michl Excel Programming 2 June 22nd 06 04:12 PM
Run worksheet module code from workbook module? keithb Excel Programming 1 August 14th 05 04:04 AM
Create a newworksheet with VBA code and put VBA code in the new worksheet module ceshelman Excel Programming 4 June 15th 05 04:37 PM


All times are GMT +1. The time now is 12:35 AM.

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"