+ Reply to Thread
Results 1 to 1 of 1

Dropdown menu, clearing dependent cells VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86

    Dropdown menu, clearing dependent cells VBA

    Hi, using the code below i have implemented an automated drop down system (ON DOUBLE CLICK), this code is meant to clear the dependent cells if the first one is changed... i.e. on the test spreadsheet If i had, say Tuesday and chips selected and then changed the Tuesday to Wednesday it will clear. This works when you press enter after changing the first cell... however this doesn't work if you change the first cell and then simply click off of it (on any cell). I've tried messing about with the code but I am unsure how to do it. Any Help is appreciated, thanks.

    Private Sub Worksheet_Change(ByVal Target As Range)
    'clear contents of dependent cells
    On Error Resume Next
    If Target.Validation.Type = 3 Then
      Application.EnableEvents = False
      Select Case Target.Column
        Case 2  'clear columns C and D
          Range(Target.Offset(0, 1), _
            Target.Offset(0, 2)).ClearContents
        Case 3  'clear column D
          Target.Offset(0, 1).ClearContents
      End Select
      
    End If
    
    exitHandler:
      Application.EnableEvents = True
      Exit Sub
    
    End Sub
    
    
    
    Private Sub TempCombo_KeyDown(ByVal _
            KeyCode As MSForms.ReturnInteger, _
            ByVal Shift As Integer)
    
            
            
            
            
    'move to next cell on Enter and Tab
    Dim varVal As Variant
    On Error Resume Next
     'change text value to number, if possible
    varVal = --ActiveCell.Value
    If IsEmpty(varVal) Then
      varVal = ActiveCell.Value
    End If
    
    Select Case KeyCode
      Case 9  'tab
        ActiveCell.Value = varVal
        ActiveCell.Offset(0, 1).Activate
      Case 13 'enter
        ActiveCell.Value = varVal
        ActiveCell.Offset(1, 0).Activate
      
      Case Else
      ActiveCell.Value = varVal
        ActiveCell.Offset(1, 0).Activate
        'do nothing
    End Select
    
    End Sub
    
    Private Sub TempCombo_LostFocus()
      With Me.TempCombo
        .Top = 10
        .Left = 10
        .Width = 0
        .ListFillRange = ""
        .LinkedCell = ""
        .Visible = False
        .Value = ""
      End With
    End Sub
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim str As String
    Dim cboTemp As OLEObject
    Dim ws As Worksheet
    Dim wsList As Worksheet
    
    Set ws = ActiveSheet
    Set wsList = Sheets("ValidationSample")
    Set cboTemp = ws.OLEObjects("TempCombo")
      On Error Resume Next
      With cboTemp
        .ListFillRange = ""
        .LinkedCell = ""
        .Visible = False
      End With
    On Error GoTo errHandler
      If Target.Validation.Type = 3 Then
       Cancel = True
        Application.EnableEvents = False
        str = Target.Validation.Formula1
        str = Right(str, Len(str) - 1)
        With cboTemp
          .Visible = True
          .Left = Target.Left
          .Top = Target.Top
          .Width = Target.Width + 15
          .Height = Target.Height + 5
          .ListFillRange = "'" & Application.Evaluate(str).Worksheet.Name & "'!" & Application.Evaluate(str).Address
          .LinkedCell = Target.Address
          
        End With
        cboTemp.Activate
      End If
      
    errHandler:
      Application.EnableEvents = True
      Exit Sub
    
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] make dropdown menu dependent on other dropdown menu values
    By kosherboy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-30-2015, 04:29 PM
  2. Clearing multiple cells with dependent validation
    By 3furballs in forum Excel General
    Replies: 0
    Last Post: 03-27-2015, 12:13 PM
  3. [SOLVED] Clearing Cells when changing dropdown list choice
    By inq80 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 12-14-2014, 07:16 AM
  4. Replies: 2
    Last Post: 07-14-2014, 05:45 AM
  5. [SOLVED] Data values dependent on selection from dropdown menu
    By atkelly in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-26-2014, 02:09 PM
  6. [SOLVED] Dependent Dropdowns, clearing dependent value when parent value changes
    By ptmald in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2013, 01:52 PM
  7. clearing a dropdown menu
    By northernstar197 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-12-2007, 01:02 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1