How to Clear a Cell Based On Another Cell

CHHeights

New Member
Joined
Dec 6, 2021
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
Hello!

I am very new to Excel so please bear with me on explaining this.

I am trying to clear a cell based on the a change to another cell. I wish to do this for each cell. What I mean is, in column G I have dates. and I want to be able to clear that date anytime I input data into the adjacent cell.
For instance:
G25 has : 1/2/2022
I want that to clear whenever I put data in cell H:25
I would like this to happen for the rest of the columns.
Screenshot (2).png

Is there anyway I can do this?

I know many people have said use a VBA code but I haven't found any for my specific needs.

Thanks so much in advance. Sorry if this isn't clear.
 

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.
Welcome to the Board!

Right-click on the sheet tab name at the bottom of your screen, select "View Code", and paste this code in the resulting VB Editor window that pops up.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.CountLarge > 1 Then Exit Sub
   
    If (Target.Column = 8) And (Target <> "") Then
        Target.Offset(0, -1).ClearContents
    End If

End Sub
Now, whenever you make a non-blank entry in column H, it will clear column G of that same row.

I would like this to happen for the rest of the columns.
If you want help with this part, you need to tell us EXACTLY which columns you are talking about.
We already know about the G/H pair, now what other columns do you want to apply this to?
 
Upvote 0
Solution
Welcome to the Board!

Right-click on the sheet tab name at the bottom of your screen, select "View Code", and paste this code in the resulting VB Editor window that pops up.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.CountLarge > 1 Then Exit Sub
  
    If (Target.Column = 8) And (Target <> "") Then
        Target.Offset(0, -1).ClearContents
    End If

End Sub
Now, whenever you make a non-blank entry in column H, it will clear column G of that same row.


If you want help with this part, you need to tell us EXACTLY which columns you are talking about.
We already know about the G/H pair, now what other columns do you want to apply this to?

Hi! Thank you so so much! This worked perfectly. I also realized I wrote columns when I meant rows, and you answered my question perfectly. Thank you so so much again. I really appreciate it!
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

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