VBA Code to clear

superfb

Board Regular
Joined
Oct 5, 2011
Messages
233
Office Version
  1. 2007
Platform
  1. Windows
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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

gallen

Well-known Member
Joined
Jun 27, 2011
Messages
2,009
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
 

superfb

Board Regular
Joined
Oct 5, 2011
Messages
233
Office Version
  1. 2007
Platform
  1. Windows
Hi that s,great however I have 100 rows...
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,781
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,089
Messages
5,857,297
Members
431,869
Latest member
Avinashz

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