Results 1 to 10 of 12

Thread: Drop-Down Menu with Multiple Conditions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    May 2020
    Posts
    66
    Rep Power
    4
    Finally SOLVED!!

    Thank you so much Alan Sir for all the help and guidance!!

    So here is the next macro version from me: https://excelfox.com/forum/showthrea...ll=1#post14875
    This macro works just wow!

    I've made some changes in the macro to fulfil the "Part B" case (Point 4,5,6)
    Part B)
    4. On clicking this cell "R19" a drop down menu appear with 5 option - "Expired" "Divorced" "Break-Up" "Abandonment" "Enter Reason Manually"
    5. On selecting an item, it appear in normal color and format
    6. On selecting "Enter Reason Manually" from this drop-down, the cell "R19" becomes empty, so that the reason can be entered manually

    This is the Macro which finally satisfies my all 7 Point needs. (red color indicates the area I've changed)


    Code:
    Private Sub Worksheet_Change(ByVal Target As Range) '   https://excelfox.com/forum/showthread.php/2624-Drop-Down-Menu-with-Multiple-Conditions?p=14873&viewfull=1#post14873
        If Target.Address = "$J$19" Or Target.Address = "$J$19:$P$19" Then  '  we need  "$J$19:$P$19"  to make macro work on  Delete  probably because of merged cells
        Dim RngTgt As Range: Set RngTgt = Target
            If Target.Address = "$J$19:$P$19" Then Set RngTgt = Range("J19")
            If RngTgt.Value = "" Then
             Let Application.EnableEvents = False
             Let RngTgt.Value = "(Select Here)"
             Let Range("R19").Value = ""
             Let Application.EnableEvents = True
             Let RngTgt.Font.Color = 10855845
        Range("R19:Z19").Select
          With Selection.Validation
            .Delete
            .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
            :=xlBetween
            .IgnoreBlank = True
            .InCellDropdown = True
            .ShowInput = True
            .ShowError = True
          End With
        Range("J19").Select
            ElseIf RngTgt.Value = "Nuclear Family" Or RngTgt.Value = "Joint Family" Then
             Let Application.EnableEvents = False
             Let Range("R19").Value = "(Remark if any)"
             Let Application.EnableEvents = True
             Let Range("R19").Font.Color = 10855845
             Let RngTgt.Font.Color = 6751362
            Range("R19:Z19").Select
          With Selection.Validation
            .Delete
            .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
            :=xlBetween
            .IgnoreBlank = True
            .InCellDropdown = True
            .ShowInput = True
            .ShowError = True
          End With
            ElseIf RngTgt.Value = "Uncategorised" Then
             Let Application.EnableEvents = False
             Let Range("R19").Value = "(Please Specify the Case)"
             Let Application.EnableEvents = True
             Let Range("R19").Font.Color = 10855845
             Let RngTgt.Font.Color = 6751362
            Range("R19:Z19").Select
          With Selection.Validation
            .Delete
            .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
            :=xlBetween
            .IgnoreBlank = True
            .InCellDropdown = True
            .ShowInput = True
            .ShowError = True
          End With
            End If
        Else
        ' Target is Not a cell to be acted on
        End If
    
        If Target.Address = "$R$19" Then Let Target.Font.ColorIndex = xlAutomatic
        
        If Target.Address = "$J$19" Then
            If Target.Value = "Single-Parent Family" Then
             Let Application.EnableEvents = False
             Let Range("R19").Value = "Select Reason..."
             Let Application.EnableEvents = True
           With Range("R19").Font
            .Color = -10477568
            .TintAndShade = 0
           End With
             Range("R19").Select
         With Selection.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="Expired,Divorced,Break-Up,Abandonment,Enter Reason Manually"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = "Error!"
            .InputMessage = ""
            .ErrorMessage = "To enter the reason manually, please select the option 'Enter Reason Manually'"
            .ShowInput = True
            .ShowError = True
          End With
               
         End If
      Else   ' Target is Not a cell to be acted on
         End If
            
         If Target.Address = "$R$19" Then
            If Target.Value = "Enter Reason Manually" Then
          With Selection.Validation
            .Delete
            .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
            :=xlBetween
            .IgnoreBlank = True
            .InCellDropdown = True
            .ShowInput = True
            .ShowError = True
          End With
             Selection.ClearContents
          With Target.Font
            .ThemeColor = xlThemeColorLight1
            .TintAndShade = 0
           End With
           Range("R19:Z19").Select
        With Selection
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlCenter
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = True
        End With
            Target.Font.Size = 11.5
         End If
      
      End If
    
    End Sub
    
    
    Sub Oops()
     Let Application.EnableEvents = True
    End Sub

    For making these changes, I've recorded the macro by Macro recorder, and then organized them in the above code.

    This macro works pretty well without any issue.

    Thanks!!
    Attached Files Attached Files
    Last edited by DocAElstein; 09-03-2020 at 03:22 PM. Reason: corrcted link in quote

Similar Threads

  1. Drop-down list of three tables
    By mahmoud-lee in forum Excel Help
    Replies: 12
    Last Post: 02-24-2014, 04:57 AM
  2. Nested If Formula With Multiple Conditions
    By lprc in forum Excel Help
    Replies: 10
    Last Post: 04-22-2013, 07:27 PM
  3. Replies: 4
    Last Post: 03-22-2013, 01:47 PM
  4. Add Macros To Custom Menu
    By mfaisalrazzak in forum Excel Ribbon and Add-Ins
    Replies: 2
    Last Post: 03-01-2013, 04:23 PM
  5. split data into multiple workbooks with 3 conditions.
    By malaionfun in forum Excel Help
    Replies: 5
    Last Post: 05-11-2012, 11:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •