+ Reply to Thread
Results 1 to 2 of 2

ActiveX ComboBox to Hide Columns

Hybrid View

  1. #1
    Registered User
    Join Date
    05-27-2019
    Location
    New York, USA
    MS-Off Ver
    Office 2016
    Posts
    1

    ActiveX ComboBox to Hide Columns

    Hello,

    I am currently having trouble making my ComboBox ActiveX hide and unhide columns based on range of text in a row. What I would like this code to do is the following:

    When a text is selected from the combo box, hide all the columns that DO NOT contain the text in rows C5:M5 and show only the columns with the text. If the combo box is empty, it should show all columns.


    This is the code I am working on:
    Private Sub ComboBox1_Change()
    
    Dim cl As Range
    Dim Rng As Range, Fnd As Range
    
    Set Target.Value = ComboBox1.Value
    
    If Target.Address(0, 0) = ComboBox1.Value Then
    If Target.Value = "" Then
    Range("C:M").EntireColumn.Hidden = False
    Else
    For Each cl In Range("C5:M5")
    cl.EntireColumn.Hidden = cl.Value <> Target.Value
    Next cl
    End If
    End If
    
    End Sub
    I keep getting an object error. Any help would be greatly appreciated. Thank you so much for your time.

    Sincerely,
    JRB
    Last edited by Leith Ross; 06-06-2019 at 06:43 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: ActiveX ComboBox to Hide Columns

    This is for an exact text match.

    Private Sub ComboBox1_Change()
        
        Dim cl        As Range
        
        If ComboBox1.ListIndex = -1 Then
            Columns("C:M").Hidden = False
        Else
            For Each cl In Range("C5:M5")
                cl.EntireColumn.Hidden = cl.Value <> ComboBox1.Value
            Next cl
        End If
        
    End Sub
    This would be a partial match (the cell contains the combbobox text).
    cl.EntireColumn.Hidden = LCase(cl.Value) Like "*" & LCase(ComboBox1.Value) & "*"
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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. error 1004 when hide/unhide rows using activex multiple combobox
    By wnd.le in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-02-2017, 06:55 PM
  2. ActiveX Combobox with multiple columns and "linking" a cell
    By Jelmer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2016, 02:00 PM
  3. [SOLVED] Hide/Unhide Columns based upon Active X Combobox value
    By stephenanderson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-30-2016, 04:36 PM
  4. Replies: 0
    Last Post: 10-26-2015, 04:25 PM
  5. ActiveX combobox datalist dependant on previous combobox selections
    By Mrs Poodle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2014, 07:07 AM
  6. [SOLVED] fill listbox (ActiveX) based combobox (ActiveX)
    By elsg in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-31-2014, 11:25 AM
  7. [SOLVED] Hide rows and columns based on a combobox value
    By yasirmusa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-23-2012, 04:52 PM

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