VBA Code to clear

superfb

Board Regular
Joined
Oct 5, 2011
Messages
105
Hi

I have the below code that deletes the dropdown next to it

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    'K5 Dropdown changes then clear l5
    
    If Target.Address(0, 0) = "K5" Then Range("L5").ClearContents
End Sub

Howcan I edit the code to delete the below drop down when they change eg k6,k7,k7
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

gallen

Well-known Member
Joined
Jun 27, 2011
Messages
2,006
Hello,

This should do it. Just add any addresses to the select statement, separated by a comma:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    'K5 Dropdown changes then clear l5
    
    'If Target.Address(0, 0) = "K5" Then Range("L5").ClearContents
    
    Select Case Target.Address(0, 0)
        Case "K5", "K6", "K7"
            Range("L" & Target.Row).ClearContents
    End Select
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,997
Office Version
  1. 365
Platform
  1. Windows
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Not Intersect(Target, Range("K5:K105")) Is Nothing Then
      Target.Offset(, 1).ClearContents
   End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,658
Messages
5,597,403
Members
414,142
Latest member
Banyangt

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
Top