Cell based dropdown list

sahana108

New Member
Joined
Dec 26, 2015
Messages
3
Hello All,
I am looking for a formula or macro,

If I select Yes in "D2", a dop down has to come in "C4", if I again change the D2 to N/A the C4 has to change to "N/A" automatically

Screenshot_31.png


I have tried with name manager, the problem is when we change the parent cell drop-down list getting updated and leaving the text what we have selected last time.

I need only when I select N/A the destination has to N/A if I select Yes a drop-down of Yes No and if I select again N/A the drop-down to disappear and N/A should come.

Would appreciate if any suggestions. Thank you..!!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
this code in the Worksheet Change event should do the trick

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r As Range, add1 As String, add2 As String
    
    Application.EnableEvents = False
    Set r = Intersect(Target, Range("D2:G2"))
    
    If r Is Nothing Then Exit Sub
        
    If Target.Value = "N/A" Then
        With Range("C" & Target.Column)
            .Validation.Delete
            .Value = "N/A"
        End With
    Else
        With Range("C" & Target.Column)
            With .Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="N/A, Yes"
                .IgnoreBlank = True
                .InCellDropdown = True
                .ShowInput = True
                .ShowError = True
            End With
            .Value = "Yes"
        End With
    End If
        
    Application.EnableEvents = True

End Sub
 
Upvote 0
this code in the Worksheet Change event should do the trick

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r As Range, add1 As String, add2 As String
   
    Application.EnableEvents = False
    Set r = Intersect(Target, Range("D2:G2"))
   
    If r Is Nothing Then Exit Sub
       
    If Target.Value = "N/A" Then
        With Range("C" & Target.Column)
            .Validation.Delete
            .Value = "N/A"
        End With
    Else
        With Range("C" & Target.Column)
            With .Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="N/A, Yes"
                .IgnoreBlank = True
                .InCellDropdown = True
                .ShowInput = True
                .ShowError = True
            End With
            .Value = "Yes"
        End With
    End If
       
    Application.EnableEvents = True

End Sub
Thanks a lot

Crystalyzer

 
Upvote 0

Forum statistics

Threads
1,215,187
Messages
6,123,540
Members
449,107
Latest member
caya

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