Excel - VBA - How to Clear Cell with an Inputted Value If A Specific Cell is Blank

CapeCon

New Member
Joined
May 10, 2021
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
I am seeking help regarding an Excel book I am working on.

What I am trying to do: When cell A6 is empty, automatically clear the inputted text in cell D6 using VBA.

Name of Sheet: Sheet2

I imagine this requires a "worksheet.change" code. I am new to VBA, so I'm not yet sure what the entire code would be for this.

Thank you!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
This is sheet code for Sheet2.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D6")) Is Nothing Then
    If IsEmpty(Range("A6")) Then
        With Application
            .EnableEvents = False
            Range("D6").Value = ""
            .EnableEvents = True
        End With
    End If
End If
End Sub
 
Upvote 0
Hi, you are right so to paste to the Sheet2 worksheet module :​
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$6" Then
        If IsEmpty(Target) Then
            Application.EnableEvents = False
            [D6].ClearContents
            Application.EnableEvents = True
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,883
Messages
6,122,077
Members
449,064
Latest member
MattDRT

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