?
Solved

VBA - Clear contens of cell, if other cells change

Posted on 2014-02-19
3
Medium Priority
?
2,667 Views
Last Modified: 2014-02-19
Hello Experts,

I am using some VBA code, but it doesn't appear to be working/running? (I have no idea how to verify its even executing)

Here is the code...

Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
        If .Address = "pmDimensions" Then
            Range("pmSeal").Value = ""
        End If
    End With
End Sub

Open in new window


pmDimensions consists of 3 cells.   Basically, if any value changes, then I want to clear the contents of pmSeal.

Any ideas what is wrong with the code above?
0
Comment
Question by:Geekamo
[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
3 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39870815
You have to turn off events for the code to behave well:

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    With Target
        If .Address = "pmDimensions" Then
            Range("pmSeal").Value = ""
        End If
    End With
    Application.EnableEvents = True
End Sub

Kevin
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 total points
ID: 39870819
Also, the Address property is not the same as the range name.

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Not Intersect(Target, Range("pmDimensions")) Is Nothing Then
        Range("pmSeal").Value = ""
    End If
    Application.EnableEvents = True
End Sub

Kevin
0
 
LVL 1

Author Closing Comment

by:Geekamo
ID: 39870855
This worked great - thanks Kevin!
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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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 …
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…

762 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