Clear cell when entering data in a different cell

box of moonlight

New Member
Joined
Dec 18, 2017
Messages
2
I need some help with VBA code on an Excel spreadsheet.

the code below only solve my problem for clearing cell "C6" when entering data in cells C5:D5. I would like it to clear cells "C5:D5" when entering data in cells C6 also.


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C5:D5")) Is Nothing Then
Range("C6").ClearContents
End If
End Sub


Thank you in advance for your help....
icon12.png
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi & welcome to the board.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
   If Not Intersect(Target, Range("C5:D5")) Is Nothing Then
      Range("C6").ClearContents
   ElseIf Target = Range("C6") Then
      Range("C5:D5").ClearContents
   End If
Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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