Make a cell either display N/A or a drop down menu based on another cell

JustHooch

New Member
Joined
May 17, 2018
Messages
44
I have been looking around and can't seem to find exactly what I'm trying to do. I know I need a VBA script to accomplish my ask.

Cell B4 contains a drop down menu
Cell B5 is dependent on B4
  • If B4 = blank then B5 = blank
  • If B4 = "Special/Hard Ticket Event" then B5 = "N/A"
  • if B4 is anything else then B5 = drop down list, name YN

Can someone help me with the VBA needed to get this done.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Adjust the data validation code to match what you need I assumed you had a list in I3:I7
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then
    If Range("B4") = "" Then
        Range("B5").Validation.Delete
        Range("B5").ClearContents
        
    ElseIf UCase(Range("B4")) = "SPECIAL/HARD TICKET EVENT" Then
        Range("B5").Validation.Delete
        Range("B5") = "N/A"
    Else
        'data valication here adjust to match what you need
        With Range("B5").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=$I$3:$I$7"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End If

End If

End Sub
 
Upvote 0
What if I needed to swap the logic?

Cell B4 contains a drop down menu
Cell B5 is dependent on B4

  • If B4 = blank then B5 = blank
  • If B4 = "Special/Hard Ticket Event" then B5 =drop down list, location tab Dropdown Values C1:C2
  • if B4 is anything else then B5 = "N/A"
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then
    If Range("B4") = "" Then
        Range("B5").Validation.Delete
        Range("B5").ClearContents
        
    ElseIf UCase(Range("B4")) = "SPECIAL/HARD TICKET EVENT" Then
         'data valication here adjust to match what you need
        With Range("B5").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="='Dropdown Values '!$C$1:$C$2"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    Else
     Range("B5").Validation.Delete
        Range("B5") = "N/A"
End If

End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,641
Messages
6,125,981
Members
449,276
Latest member
surendra75

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