Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

link three dropdown depend on each other of them

0

hello

my question  I no  Know  if  it's possible  I know  this is  possible in combobox   but  I would  that  by  dropdown  if  it's  possible  it will be  great   in my  file  I have  three dropdowns in columns A,B,C  what  Iwant  if  i  select   US from COL A then should only show Arizona and when select from COL B  then should only show Alberta in COL C 

short in words Whatever he chose from the first list, the corresponding value should appear without showing any other values in the second column. Likewise, when he chose from the second list, the corresponding value is shown without showing any other values

Answer
Discuss

Answers

0
Selected Answer

 In the validation specs of B2 enter the formula below in place of the existing cell reference.

=INDEX(INDIRECT($A$2),,1)

This will apply a different list to the drop-down depending upon the choice in A2. Note that the ranges are named as listed in E2:E3, which is the validation source for A2 - all as existing in your workbook. You also already have an even procedure which will change the selection from the list.

In this procedure you might replace the Select statement with the line below.

Range("B2").Value = Range(Target.Value).Cells(1).Value

This code would just insert the first item from the selected list. If the list doesn't exist the code would crash. One way to avoid that would look like this:-

On Error Resume Next
Range("B2").Value = Range(Target.Value).Cells(1).Value
If Err Then Range("B2").ClearContents

Below is an implementation of that idea.

Option Explicit
Option Compare Text     'makes macro non-case-sensitive

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Count = 1 Then
        If Target.Address = "$A$2" Then
            Application.EnableEvents = False
            On Error Resume Next
            Range("B2").Value = Range(Target.Value).Cells(1).Value
            If Err Then Range("B2").ClearContents
            Application.EnableEvents = True
        End If
    End If
End Sub
Discuss

Discussion

thanks  for  your  trying  help  me    actually   it  shows  abig  problem the  code   would  crash  when   I run  despite   I attach  the code  what  you  suggested   to  doesn't happen this problem  
MAKLIL (rep: 34) Mar 15, '21 at 5:11 am
I tested the code I gave you. It doesn't crash. I also tested my suggestion in your workbook - again - and it works perfectly. 
Therefore, the thing to do is to first check your installation of my suggestions. Then, if you can't find the mistake, post your workbook which crashes. For good measure, also make sure to say how and where he crash occurs. (Any highlighted code? Any error message?)
I have added a complete version of the event procedure. Perhaps that's where you had a problem.
Variatus (rep: 4889) Mar 15, '21 at 5:37 am
yes ,  now  it  works  very  well  
thanks for  your  solution 
MAKLIL (rep: 34) Mar 15, '21 at 6:39 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login