Solved

Excel VBA - spreadsheet locking every time Sheet_Change event code runs

Posted on 2012-04-11
2
310 Views
Last Modified: 2012-04-11
Hi.
My spreadsheet is locking every time Sheet_Change event code runs when I change a cell
Excel end up failing. The two offending lines are
  Sh.Cells(6, 6) = oCountNew
   Sh.Cells(8, 6) = oCountUsed



Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim oCount_New As Integer
    Dim oCount_Used As Integer
   
    If Target.Column = 6 And Sh.Name <> "SUMMARY" Then
     
        oCountUsed = Application.WorksheetFunction.CountIf(Range("F22:F1000"), "U")
        oCountNew = Application.WorksheetFunction.CountIf(Range("F22:F1000"), "N")
        Sh.Cells(6, 6) = oCountNew
        Sh.Cells(8, 6) = oCountUsed
       
    End If
   
End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 37835114
Since the code is changing cells it calls itself.

To stop that happening add this at the start,
Application.EnableEvents = False

Open in new window

and this at the end.
Application.EnableEvents = True

Open in new window


It's important that you add that at the end, if you don't no other events will be triggered after the code is finished.
0
 

Author Closing Comment

by:murbro
ID: 37835139
Thanks very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now