Hide Cell in selection if not in listbox

  • Hi,


    This code is running in a userform. The logic I'm trying to code is:


    If Activecell's value is not in the listbox then hide the entire row.


    Here is my code thus far:


    The code appears to be doing what I need it to do overall BUT I cant get the active cell value to equal the list value (at the *** comment section in the code above).
    Even when the message box statement shows me that both variables are the same, the code at the *** comment wont move to my "then" statement.


    I don't get any errors at runtime.


    Anyone have any ideas what I'm doing wrong here?


    Thanks,


    -Craig

  • Re: Hide Cell in selection if not in listbox


    Hi,


    You could use the Scripting Dictionary to check if the value exists before you hide the row.


    Try the following example.



    HTH


    C

  • Re: Hide Cell in selection if not in listbox


    I just tested your code and no rows were hidden when the line below was executed.

    Code
    wks.Cells(lngRow, 1).EntireRow.Hidden = True


    So can I assume, based on this test, that the value does not exist? And if mycode is not going to work is there a better alternative to accomplish what I'm trying to do? (Hiding rows with values that <> to any of the listbox values)


    Thanks,


    -Craig

  • Re: Hide Cell in selection if not in listbox


    Could someone take a look at this for me? I feel like its might be something small I'm overlooking.


    Thanks,


    -Craig

  • Re: Hide Cell in selection if not in listbox


    The way I have it set up is to hide the row initially and then if the activecell's value is equal to one of the list values then unhide the row.


    I figured it would be easier than hiding the row if it was not on the list, but I could be wrong.


    Thanks,


    -Craig

  • Re: Hide Cell in selection if not in listbox


    Hi,


    Still looking for some feedback here, I will take another look at it tonight and see what I can do.


    Thanks,


    -Craig

  • Re: Hide Cell in selection if not in listbox


    Solved:


    I was missing "CStr(...)"

    Code
    If ActiveCell.Value = CStr(Ctrl.List(j)) Then ActiveCell.EntireRow.Hidden = False


    -Craig

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!