How to clear specified cell contents if value of another cell changes in Excel?
Supposing you want to clear a range of specified cell contents if the value of another cell is changed, how can you do? This post will show you a method to solve this problem.
Excel Productivity Tools
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately. 60-day Unlimited Free Trial
As below screenshot shown, when the value in cell A2 is changed, contents in cell C1:C3 will be cleared automatically. Please do as follows.
1. In the worksheet you will clear cell contents based on another cell changes, right click the sheet tab and select View Code from the context menu. See screenshot:
2. In the opening Microsoft Visual Basic for Applications window, copy and paste below VBA code into the Code window.
VBA code: Clear specified cell contents if value of another cell changes
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A2")) Is Nothing Then Range("C1:C3").ClearContents End If End Sub
Note: In the code, B2 is the cell you will clear cell contents based on, and C1:C3 is the range you will clear contents from. Please change them as you need.
3. Press the Alt + Q keys to close the Microsoft Visual Basic for Applications window.
Then you can see contents in range C1:C3 is cleared automatically when the value in cell A2 changes as below screenshot shown.
- How to clear contents of combo box with VBA code in Excel?
- How to clear contents and formatting at the same time in cells in Excel?
- How to clear contents of named range in Excel?
- How to clear restricted values in cells in Excel?
- How to clear specified cell contents on open and exit in Excel workbook?
Excel Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 19 days agoany way of doing this without VBA?
To post as a guest, your comment is unpublished.· 2 months agoIn the case of A2, how do i reference a cell from a different worksheet?
To post as a guest, your comment is unpublished.
To post as a guest, your comment is unpublished.· 11 months agoHi, I'm looking for a way to clear a range of cells of data when an "x" is entered in a certain cell. I used the above formula and it worked perfectly for that one row. The problem is that I need to extend it down to many rows. For example, if an "x" is entered in "D13", I need the range J:13 - v:13 to be cleared. I also need that to happen if an x is entered in "D14" as in I need the range d:14 - v:14 to be cleared. Is there a way to write that? Thanks for your help!
To post as a guest, your comment is unpublished.· 1 years agohello, this works for a fixed source cell only (A2), how do this dynamically such as source is a variable cell? i tried to write
If Not Intersect(Target, Range("A"& A)) Is Nothing Then
this should do the job with regard to activecell (ie selection) but is not working
To post as a guest, your comment is unpublished.· 1 years agoGood Day,
Please try the below VBA code. Thank you for your comment.
Private Sub Worksheet_Change(ByVal Target As Range)
If (Not Intersect(Target, Rows(1)) Is Nothing) And (Target.Count = 1) Then