?
Solved

Excel VBA - spreadsheet locking every time Sheet_Change event code runs

Posted on 2012-04-11
2
Medium Priority
?
315 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Norie earned 2000 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:Murray Brown
ID: 37835139
Thanks very much
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

800 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