Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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.

Clear specified cell contents if value of another cell changes with VBA code

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


Clear specified cell contents if value of another cell changes with VBA code


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.


Related articles:


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, and Help You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for you.

  • Designed for 1500+ work scenarios, helps you solve 80% Excel problems.
  • Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
  • Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
  • 60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  • Being used by 110,000 elites and 300+ well-known companies.

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Sonia · 19 days ago
    any way of doing this without VBA?
  • To post as a guest, your comment is unpublished.
    GQ · 2 months ago
    In the case of A2, how do i reference a cell from a different worksheet?
  • To post as a guest, your comment is unpublished.
    Mac · 10 months ago
    Hi this isnt working for mine. Nothing changes but no errors either. Any tips?
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      Good day,
      Sorry for the inconvenience. Would you provide your Office version? Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    Jason · 11 months ago
    Hi, 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.
    Mat 257 · 1 years ago
    hello, this works for a fixed source cell only (A2), how do this dynamically such as source is a variable cell? i tried to write
    A=activecell.row
    If Not Intersect(Target, Range("A"& A)) Is Nothing Then
    Range("C1:C3").ClearContents
    End If

    this should do the job with regard to activecell (ie selection) but is not working
    thanks
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Good 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
      Range("C1:C3").ClearContents
      End If
      End Sub