VBA code help, changes in specific cells trigger changes

Ben2000

New Member
Joined
Mar 8, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all,

I have dependent dropdown lists and need to have the corresponding dropdown list cleared when the primary selection changes.

I am trying to use VBA code to do this and went through some programming material, but I cannot see how to reference these. I.e.

Anything changes in Cell D16 onwards, then the corresponding cell in E should to state "Please select..."

So, if D16 changes, then E16 is automatically changed to "Please select".

Any help possible?

Many thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
What do you want in E16 if a value in D16 is deleted?
 
Upvote 0
Hello Joe,

Thanks for looking into this. It is like this:

D16 has product group, say fruits, and vegetables
E16 has the specific item, e.g. specific fruit OR specfic vegetables

So, basically, if D16 changes from Fruits to Vegetables, then I want the adjoining cell E16 to basically reset itself to show, "Please select" a new value.

And then I am using conditional formatting to highlight all cells that have "Please select" as the value. Basically trying to ensure that peaches don't land up being vegetables.
 
Upvote 0
You didn't answer my question so I'll assume you want E16 to be blank if the user deletes the value in D16.
This code is for the sheet holding the dropdowns. Right-click the sheet tab, choose 'View Code' and paste the code into the white space that appears in the VBE window.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, lRw As Long
lRw = Target(Target.Count).Row
If lRw < 16 Then Exit Sub
If Not Intersect(Target, Range("D16:D" & lRw)) Is Nothing Then
    Application.EnableEvents = False
    For Each c In Intersect(Target, Range("D16:D" & lRw))
        If Not IsEmpty(c) Then
            Cells(c.Row, c.Column + 1).Value = "Please select"
        Else
            Cells(c.Row, c.Column + 1).Value = ""
        End If
    Next c
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Solution
Thanks a ton Joe, much appreciated, works like a charm! BTW, any good resources for learning the art of scripting that you have done?
 
Upvote 0
Thanks a ton Joe, much appreciated, works like a charm! BTW, any good resources for learning the art of scripting that you have done?
You are welcome - thanks for the reply. There are lots of tutorials on the internet- google 'VBA for Excel'.
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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