Clear dependent drop down lists - 2 different comands

redd3452

New Member
Joined
Apr 19, 2018
Messages
2
I have been able to find a code to clear dependent drop down lists. However I'm not sure how to combine two commands. I have it set to currently clear the contents of E, F, and G if columns D, E, F, or G are changed. The code I'm using for this is below and works fine.
However I want a separate command that has column B and C cleared if A is changed, and column C cleared if B is changed.
Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
'clear contents of dependent cells
On Error Resume Next
If Target.Validation.Type = 3 Then
  Application.EnableEvents = False
  Select Case Target.Column
    Case 4  'clear columns E and F and G
      Range(Target.Offset(0, 1), _
        Target.Offset(0, 3)).ClearContents
    Case 5  'clear column F and G
      Range(Target.Offset(0, 1), _
        Target.Offset(0, 2)).ClearContents
    Case 6  'clear column G
      Target.Offset(0, 1).ClearContents
  End Select
End If


exitHandler:
  Application.EnableEvents = True
  Exit Sub


End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi & welcome to the board.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   'clear contents of dependent cells
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Validation.Type = 3 Then
      Application.EnableEvents = False
      Select Case Target.Column
         Case 1
            Target.Offset(, 1).Resize(, 2).ClearContents
         Case 2
            Target.Offset(, 1).ClearContents
         Case 4  'clear columns E and F and G
            Range(Target.Offset(0, 1), _
            Target.Offset(0, 3)).ClearContents
         Case 5  'clear column F and G
            Range(Target.Offset(0, 1), _
            Target.Offset(0, 2)).ClearContents
         Case 6  'clear column G
            Target.Offset(0, 1).ClearContents
      End Select
   End If
   Application.EnableEvents = True
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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