VBA to Remove Cell Content If another Cell is null

808excel

New Member
Joined
Oct 4, 2019
Messages
21
Hi,

I'm trying to have cell A2 clear it's contents only IF cell A1 is null. So the user will make a selection in cell A1 and then they can make a selection in A2, but I want it to remove their selection in A2 if they remove their selection in A1. I tried using the following, but it will always remove A2 whenever A1 is updated.

If Not Intersect(Target, Range("A1")) Is Nothing Then

Application.EnableEvents = False
Range("A2").ClearContents = Target <> "Yes"

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I am not 100% clear on what you are trying to do (especially your test against the text "Yes" given your first sentence), but let me take a guess (if I am correct, then this code would replace what you posted)...

VBA Code:
If Target.Address(0, 0) = "A1" Then
  If Target.Value = "" Then Target.Offset(1).ClearContents
End If
 
Upvote 0
I am not 100% clear on what you are trying to do (especially your test against the text "Yes" given your first sentence), but let me take a guess (if I am correct, then this code would replace what you posted)...

VBA Code:
If Target.Address(0, 0) = "A1" Then
  If Target.Value = "" Then Target.Offset(1).ClearContents
End If

Thanks! I got this to work. I think the issue I had was with how I nested the If statements.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

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