+ Reply to Thread
Results 1 to 12 of 12

Combo box selection hides columns that do not match

Hybrid View

  1. #1
    Registered User
    Join Date
    09-05-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2010
    Posts
    6

    Combo box selection hides columns that do not match

    Hi all,

    Need some VBA help with hiding columns based on a combo box selection. The Combo box currently has roughly 30 selections and could increase over time. I would like to have the user select a value in the comb box and the code find the cell value (text) that matches and hide all other columns.

    Any help is greatly appreciated.

    Thanks,
    Nick

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Combo box selection hides columns that do not match

    is the combobox on a userform or on a sheet?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    09-05-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Combo box selection hides columns that do not match

    It is on a sheet

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Combo box selection hides columns that do not match

    Sub test()
    
    Dim l As Long
    Dim ll As Long
    Dim bCheck As Boolean
    
    For l = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
        bCeck = False
        For ll = 1 To Cells(Rows.Count, 1).End(xlUp).Row
            If InStr(1, Me.ComboBox1.Value, Cells(ll, l).Value) > 0 Then
                bCeck = True
            End If
        Next ll
        If bCheck = False Then Cells(1, l).EntireColumn.Hidden = True
    Next l
            
    End Sub
    You can try this. Assuming your combobox is named ComboBox1.
    Last edited by Solus Rankin; 09-05-2013 at 06:43 PM.

  5. #5
    Registered User
    Join Date
    09-05-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Combo box selection hides columns that do not match

    Solus,

    I have copied your code in, when I select a value in the combobox it does not hide the non-associated columns. However if you select the blank part of the drop down it will hide column A.

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Combo box selection hides columns that do not match

    where did you copy the code to? what are you using to trigger the code?

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Combo box selection hides columns that do not match

    where did you copy the code to? what are you using to trigger the code?

  8. #8
    Registered User
    Join Date
    09-05-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Combo box selection hides columns that do not match

    I have attached an example of what I am working on. ComboBox3 is the topic of this thread.




    Price List Example.xlsm

  9. #9
    Registered User
    Join Date
    09-05-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Combo box selection hides columns that do not match

    It is copied on Sheet8's code page. I'm not sure what you mean about triggering the code....

  10. #10
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Combo box selection hides columns that do not match

    Price%20List%20Example.xlsm Sorry about the duplicate post.

    Basically you're trying to hide all columns where the header doesnt match combobox3 correct?

    try the attachment.

  11. #11
    Registered User
    Join Date
    09-05-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Combo box selection hides columns that do not match

    Works Perfect! Thanks for your help!

  12. #12
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Combo box selection hides columns that do not match

    Glad to help.

+ 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. Replies: 5
    Last Post: 06-21-2013, 08:42 AM
  2. Need help with creating a command box in excel (VBA code) that hides combo boxes
    By aritops in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-29-2012, 08:45 AM
  3. [SOLVED] Combo box selection displays textboxes or hides them, help please.
    By RTR97 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2012, 12:31 PM
  4. Line that expands/hides columns
    By Analyst99 in forum Excel General
    Replies: 1
    Last Post: 03-13-2007, 08:25 AM
  5. Button hides unhides columns, how?
    By JimH in forum Excel General
    Replies: 3
    Last Post: 04-20-2005, 05:06 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