Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel VBA - spreadsheet locking every time Sheet_Change event code runs

Posted on 2012-04-11
2
Medium Priority
?
316 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
2 Comments
 
LVL 35

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

886 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