View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default How to prevent routine from running on certain sheets

I didn't try to run your code but it looks to me that the problem may be
that the formatting is done to the "activesheet". The sheet deactivate
event runs after you've left a sheet. So another sheet is therefore active.
You're formatting the new sheet, not the old one.

I'd try passing the sheet to Calc_New_Expenses like :

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)

If Sh.Name = "Construction Expenses" Or Sh.Name = "Misc Expenses" Then
Calc_New_Expenses Sh
End If

End Sub


Sub Calc_New_Expenses(Sh as Worksheet)
Dim MyRange As Range, MyRows As Integer, ThisRow As Integer
''other code

With Sh
Set MyRange = .UsedRange
MyRows = MyRange.Rows.Count
'etc
End With

End Sub

Jim Rech
Excel MVP