Consulting

Results 1 to 6 of 6

Thread: How to make my combobox invisible

  1. #1

    How to make my combobox invisible

    Hello,

    I am struggling with the code to make my combobox disappear

    I want my combobox to appear when N6 = 1. In all other cases, it should disappear.

    But my code doesn't work...

    Ths is my code:
    Private Sub Combobox_visible()
    If Range("N6").Value = 1 Then
    Me.ComboBox1.Visible = True
    Else
    Me.ComboBox1.Visible = False
    End If
    End If
    End Sub

    See file in attachment

    Can someone please help me with this?

    Thank you!
    Attached Files Attached Files

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    How/when are you running the code? (It won't run automatically)
    Be as you wish to seem

  3. #3
    Three examples of using worksheet events to control combobox visibility based on a cell value

    
    Private Sub Worksheet_Activate()
        ComboBox1.Visible = Range("N6").Value = 1
    End Sub
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        ComboBox1.Visible = Range("N6").Value = 1
    End Sub
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        ComboBox1.Visible = Range("N6").Value = 1
    End Sub

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    This is sufficient:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        ComboBox1.Visible = [A1]
    End Sub
    If A1 =0, then Combobox1<>visible.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    I'd do it this way

    I think some code was not in the right events and I had some screen ghosts when I was testing (could be my video driver though)

    I don't like to put a simple one cell test in _SelectionChange since that event fires everytime. I prefer just _Change


    Option Explicit
    
    Private Sub ComboBox1_Change()
        Range("G6").Value = Me.ComboBox1.Value
    End Sub
    
    
    
    Private Sub Worksheet_Activate()
        ComboBox1.ListFillRange = "Dropdownlist"
        Call pvtShowCombobox(Range("N6").Value = 1)
    End Sub
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("N6")) Is Nothing Then Exit Sub
        Call pvtShowCombobox(Range("N6").Value = 1)
    End Sub
    
    
    Private Sub pvtShowCombobox(b As Boolean)
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        ComboBox1.Visible = b
        Application.ScreenUpdating = True
        Application.EnableEvents = True
        DoEvents
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi Mientje08
    M6 and N6 can be deleted if they are of no other use.
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Row <> 6 Then Exit Sub
    If Target.Column <> 3 And Target.Column <> 5 Then Exit Sub
    ComboBox1.Visible = [c6] & [e6] = "DealerYes"
    End Sub

Posting Permissions

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