How to clear contents of a cell when another is changed (VBA)

ahungria

New Member
Joined
Aug 4, 2010
Messages
6
Hi,
I am using drop down boxes (validation) and i want to clear the contents of 1 drop down cell when another drop down cell changes. Below is a code that works when i just click on the cell, but i want to modify it to be when a change occurs, not just with a click.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Count > 1 Then Exit Sub
If Target.Address = "$D$17" Then <-- this is the cell that is changed
Range("D21").ClearContents <-- this is the cleared cell
End If
End Sub

Im using Excel 2003. Thank you for the help!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range

    For Each Cell In Target
        If Cell.Address = "$D$17" Then 
            Application.EnableEvents = False
                Range("D21").ClearContents
            Application.EnableEvents = True
    Next Cell

End Sub
 
Upvote 0
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range

    For Each Cell In Target
        If Cell.Address = "$D$17" Then 
            Application.EnableEvents = False
                Range("D21").ClearContents
            Application.EnableEvents = True
        End If
    Next Cell

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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