Clear cell contents if another cell changes

rayzorkat

New Member
Joined
Feb 26, 2018
Messages
4
On my dependent list, I want to clear cell contents if another cell changes.

It works if I change the "Type" to clear "Style" and "Color".

However, I cannot figure out how to clear "Color" if "Style" only changes.

Here's the code I'm using:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("d2:g2")) Is Nothing Then
Range("d4:g4").ClearContents
Range("d6:g6").ClearContents
End If
End Sub


1635872980253.png
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Welcome to the Board!

First of all, get rid of the merged cells and use the "Center Across Selection" formatting option instead.
Merged cells are the devil, and will cause you noting but headaches.
See here: Tom’s Tutorials For Excel: Using Center Across Selection Instead of Merging Cells – Tom Urtis

Then, use this code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.CountLarge > 1 Then Exit Sub
    
    Application.EnableEvents = False
    
    Select Case Target.Address(0, 0)
        Case "D2"
            Range("D4").ClearContents
            Range("D6").ClearContents
        Case "D4"
            Range("D6").ClearContents
    End Select
    
    Application.EnableEvents = True

End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top