+ Reply to Thread
Results 1 to 7 of 7

ComboBox Linked Cell change does not trigger hiding/unhiding of columns

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-23-2014
    Location
    Fredericia, Denmark
    MS-Off Ver
    Windows Office 2013, Excel 10
    Posts
    139

    ComboBox Linked Cell change does not trigger hiding/unhiding of columns

    I'm using an Active X combobox ("GLC_Code") to reference a list of staff codes and have assigned a cell ("D1") to match whatever is selected in the combobox. Based on what is in "D1" different columns should hide/unhide. Except they don't....However, if I make a change in the combobox then double click in the (also changed/matching) linked cell and then double click in any other cell then the hiding/unhiding event is triggered, as scripted. I'm pretty sure I'm overlooking something simple but the neurons aren't firing well today. Here is my code:

    Option Explicit
    
    Private Sub GLC_Code_Change()
    
    End Sub
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Application.ScreenUpdating = False
        If Target.Address = "$D$1" Then
            Select Case Target.Value
            Case Is = "Designer GLC 1"
                Range("B:B").EntireColumn.Hidden = False
                Range("C:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 2"
                Range("C:C").EntireColumn.Hidden = False
                Range("B:B").EntireColumn.Hidden = True
                Range("D:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 3"
                Range("D:D").EntireColumn.Hidden = False
                Range("B:C").EntireColumn.Hidden = True
                Range("E:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 4"
                Range("E:E").EntireColumn.Hidden = False
                Range("B:D").EntireColumn.Hidden = True
                Range("F:R").EntireColumn.Hidden = True
           End Select
            Application.ScreenUpdating = True
        End If
    End Sub
    Also, I tried several configurations to list the series of columns in one line but nothing worked. Suggestions?


    Thanks for your help. David

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: ComboBox Linked Cell change does not trigger hiding/unhiding of columns

    Hi David,

    The easiest way is probably to change the Worksheet_Change() event to a ComboBox Change Event "GLC_Code_Change(). Your code didn't work because cell 'D1' changed based on a formula and that does not generate a 'Change Event'. It generates a 'Calculate Event'. The 'Calculate Event' does not have a 'Target' cell, so a good deal of additional code is required to determine if cell 'D1' changed. If you're interested in how this works, see the file associated with post #3 in the following thread: http://www.excelforum.com/excel-prog...ionchange.html

    There are more efficient ways to list a series of columns, but I prefer the way you have it, because I think it is very easy to read.

    Lewis
    Last edited by LJMetzger; 12-10-2014 at 05:48 PM. Reason: Added Worksheet_Calculate() info

  3. #3
    Forum Contributor
    Join Date
    05-23-2014
    Location
    Fredericia, Denmark
    MS-Off Ver
    Windows Office 2013, Excel 10
    Posts
    139

    Re: ComboBox Linked Cell change does not trigger hiding/unhiding of columns

    I don't understand, sorry. I reviewed the third post from the link you forwarded but it didn't seem to fit exactly what I am (trying) to do. My problem is that nothing happens (no columns hide/unhide) when the content (text, not numerical values) of the cell linked to a ComboBox changes (when a different listing in that Combobox is selected.) If I double click in the linked cell and then double click in any other cell, then the hiding/unhiding works. Specifically, what am I doing wrong with my code, please?

    I'm sure this is a very basic question but I've searched for several hours online and have found nothing that works. I'm very frustrated...

    Thanks for your help. David

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: ComboBox Linked Cell change does not trigger hiding/unhiding of columns

    Hi David,

    I did all that I could with the code you provided. For additional help, you're going to have to upload a sample workbook, that contains your code in context.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    Lewis

  5. #5
    Forum Contributor
    Join Date
    05-23-2014
    Location
    Fredericia, Denmark
    MS-Off Ver
    Windows Office 2013, Excel 10
    Posts
    139

    Re: ComboBox Linked Cell change does not trigger hiding/unhiding of columns

    Here is the document. It's pretty brief. Note the location of the cell is, purely by coincidence, "U2".... not "D1" as indicated in my original inquiry.

    Thanks for your help Lewis. I really appreciate it. David
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: ComboBox Linked Cell change does not trigger hiding/unhiding of columns

    Hi David,

    Try this in the Scorecard_New module. It worked for me. If it doesn't work, we have to:
    a. Verify the properties in the Combobox (i.e. linked cell, and make sure it triggers the GlC_Code_Change() event()).
    b. Make sure the Sheet isn't corrupt.

    The Worksheet_Change() event is not triggered when 'U2' changes, because a formula changes the value of 'U2'. However, when the ComboBox changes value, the GLC_Code_Change() event is triggered. I had to make minimal changes to make it work. Changes in red.


    Option Explicit
    
    Private Sub GLC_Code_Change()
      Debug.Print "GLC_Code_Change at " & Now
            Application.ScreenUpdating = False
            Select Case GLC_Code.Value
            Case Is = "Designer GLC 1"
                Range("B:B").EntireColumn.Hidden = False
                Range("C:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 2"
                Range("C:C").EntireColumn.Hidden = False
                Range("B:B").EntireColumn.Hidden = True
                Range("D:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 3"
                Range("D:D").EntireColumn.Hidden = False
                Range("B:C").EntireColumn.Hidden = True
                Range("E:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 4"
                Range("E:E").EntireColumn.Hidden = False
                Range("B:D").EntireColumn.Hidden = True
                Range("F:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 5"
                Range("F:F").EntireColumn.Hidden = False
                Range("B:E").EntireColumn.Hidden = True
                Range("G:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 6"
                Range("G:G").EntireColumn.Hidden = False
                Range("B:F").EntireColumn.Hidden = True
                Range("H:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 7"
                Range("H:H").EntireColumn.Hidden = False
                Range("B:G").EntireColumn.Hidden = True
                Range("I:R").EntireColumn.Hidden = True
            Case Is = "Designer GLC 8"
                Range("I:I").EntireColumn.Hidden = False
                Range("B:H").EntireColumn.Hidden = True
                Range("J:R").EntireColumn.Hidden = True
            Case Is = "Engineer GLC 1"
                Range("J:J").EntireColumn.Hidden = False
                Range("B:I").EntireColumn.Hidden = True
                Range("K:R").EntireColumn.Hidden = True
            Case Is = "Engineer GLC 2"
                Range("K:K").EntireColumn.Hidden = False
                Range("B:J").EntireColumn.Hidden = True
                Range("L:R").EntireColumn.Hidden = True
            Case Is = "Engineer GLC 3"
                Range("L:L").EntireColumn.Hidden = False
                Range("B:K").EntireColumn.Hidden = True
                Range("M:R").EntireColumn.Hidden = True
            Case Is = "Engineer GLC 4"
                Range("M:M").EntireColumn.Hidden = False
                Range("B:L").EntireColumn.Hidden = True
                Range("N:R").EntireColumn.Hidden = True
            Case Is = "Engineer GLC 5"
                Range("N:N").EntireColumn.Hidden = False
                Range("B:M").EntireColumn.Hidden = True
                Range("O:R").EntireColumn.Hidden = True
            Case Is = "Engineer GLC 6"
                Range("O:O").EntireColumn.Hidden = False
                Range("B:N").EntireColumn.Hidden = True
                Range("P:R").EntireColumn.Hidden = True
            Case Is = "Engineer GLC 7"
                Range("P:P").EntireColumn.Hidden = False
                Range("B:O").EntireColumn.Hidden = True
                Range("Q:R").EntireColumn.Hidden = True
            Case Is = "Engineer PLDL"
                Range("Q:Q").EntireColumn.Hidden = False
                Range("B:P").EntireColumn.Hidden = True
                Range("R:R").EntireColumn.Hidden = True
            End Select
            Application.ScreenUpdating = True
    End Sub
    Lewis

  7. #7
    Forum Contributor
    Join Date
    05-23-2014
    Location
    Fredericia, Denmark
    MS-Off Ver
    Windows Office 2013, Excel 10
    Posts
    139

    Re: ComboBox Linked Cell change does not trigger hiding/unhiding of columns

    Shazam! That did it. Thanks for your Lewis. You rock. David

+ 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. Hiding/Unhiding Columns referencing a cell with a formula
    By nabeel.pnm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2012, 03:00 AM
  2. Hiding unhiding columns
    By ABSTRAKTUS in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2010, 11:24 AM
  3. Hiding and Unhiding Entire Columns based on Cell Reference
    By montego in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-02-2010, 01:25 PM
  4. Hiding / Unhiding rows when multiple cell values change
    By waverider in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2006, 08:35 AM
  5. [SOLVED] Hiding/Unhiding Columns
    By xkarenxxxx in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-05-2006, 09:25 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