Hide Or Filter Rows Based On Cell Value

  • Re: Hide Or Filter Rows Based On Cell Value


    Code
    If  Intersect(Target(1, 1), Range("[B]C4[/B]:I4")) Then

    Should be

    Code
    If  Intersect(Target(1, 1), Range("[B]B4[/B]:I4")) Then

    Which is now is in my second code.


    You also need to change the criteria range Names to MyCriteria1, MyCriteria2 etc

  • Re: Hide Or Filter Rows Based On Cell Value


    Thank you so much! I should have been able to spot that.....my bad.


    I had to change the > sign to a < sign because I needed the rows to hide that were greater than cell value.


    Everything is working great except for entering in 0. I can imput any number in B4 and it will add the < sign and filter accordingly, but when I enter in 0 the < sign goes away and the cells are not restored. I have to enter in 36 to restore the hidden cells.


    Other than that this is great!!

  • Re: Hide Or Filter Rows Based On Cell Value


    Yeah I thought "<" was the less than sign, but it hides the rows greater than the number when I switched the sign from > to <.


    When I enter in 23, the cell now says <=23, and it hides rows 24-35 like I need it to. When the sign was the other way >=23, it hid rows 1-22. I don't know why. Mathematically it does not make sense, but it is working, so I will let that detail go.


    I noticed the wrong rows being hidden, so I switched the sign, and when it worked, I thought maybe I was wrong on which one was the greater than sign. But glad to know my math skills are NOT that horrible. :P


    Thanks again!

  • Re: Hide Or Filter Rows Based On Cell Value


    Sorry about the cross posting. I thought I had deleted that forum because I could not get the attachment to work. I apologize. I didn't even realize that forum was still going on until I saw the cross posting reference here.


    I contacted the administrator to delete it because it would not let me delete it myself. I guess the message was not received; I am sorry.



    PS: In the future if I need to cross post, would I just put the URL of the other thread forum in my initial message here? Or do I put this thread forum URL in the mr. excel board or both?


    Last time I tried to cross reference I apparently did it wrong, so I was trying to avoid cross referencing.

  • Re: Hide Or Filter Rows Based On Cell Value


    Oops....one more error.


    I entered in a students name in cell A10, and it returned the <= formula in front of it. (EX. <=Cano, Juan).


    I do not want the <= sign to appear in front of students names. I only need the <= to appear in cells B4:I4.


    The line inserting the <= sign is:


    Code
    Target(1, 1) = "<=" & Target(1, 1)


    I thought Target(1,1) was only being referenced as the range B4:I4 with this line:


    Code
    If Intersect(Target(1, 1), Range("B4:I4")) Then


    But somehow the code is entering <= sign in ANY and ALL cells I enter data into. I enter stuff into random cells throughout the spreadsheet, and whatever I entered was always proceeded with <=.


    When you fix it, can you also explain it to me. I really want to learn.

  • Re: Hide Or Filter Rows Based On Cell Value


    I was able to fix that error, but there is another that I did discover until today. I have the number of students for period one entered in C5, and for period two in E5. When I enter in 25 in C5, it will hide the last 10 rows for period one table, but when I enter 25 in E5, it unhides period one rows, and hides the last 10 rows for period two. I need both tables to have the rows hidden, but it will only hide the last one entered in. So when I enter in period 8, it unhides period 1-7, and only hides period 8.


    Here is the code, I am using. The cells are spread out because I created columns to hold information that is hidden.



    I need to be able to hide all the period table rows not just one at a time.

  • Re: Hide Or Filter Rows Based On Cell Value


    Quote

    I need both tables to have the rows hidden, but it will only hide the last one entered in. So when I enter in period 8, it unhides period 1-7, and only hides period 8.


    I may be mistaken ( happens often :wink: ), but I think Advanced Filter will only work with one range at any time. Thus it will "turn itself off" for the current range when you next apply it to another range. If I am in error Dave, or another OzMVP, will clarify this.


    Although the below code is not as elegant as the much to be preferred Select Case Method, it will get the job done:


  • Re: Hide Or Filter Rows Based On Cell Value


    AAE, is correct (as usual :) ) that only 1 Filter at a time per Worksheet. This why I stated;

    Quote

    I have edited the code so a zero in B4 will unhide ALL rows hidden by ANY filters.

  • Re: Hide Or Filter Rows Based On Cell Value


    Yes that worked great thanks!


    However, I also need to add code that HIDES columns based on a cell value.


    The rows represent the amount of students, and the columns represent the amount of assessments given each unit. Since every teacher has a different amount of assessments, I also need columns to hide.


    I tried to append this code to the same code you gave me changing the values from where we left off, but it did not work.



    I had changed c1 to be c9 since I had left off with c8 for the 8th period. But that ended up causing problems with the period rows not being hidden.


    How would I add this column coding onto your row coding that you gave me.
    (There are 5 units, so there are going to be 5 column codes; this is just the first two)

  • Re: Hide Or Filter Rows Based On Cell Value


    Your adaptation of the code will not work for at least two reasons:

    • In the code to hide rows: column-C contains a numeric value for each row where as your the code to hide columns the row (#8) you reference does not contain numerical values that can be evaluated. And even if it did, it leads to the following problem.
    • You include column-P in your range of columns to hide and cell P8 appears to be the input cell to trigger the code. Once this column is hidden you would not be able to input a new value to trigger an event to change the hidden/unhidden status of the columns.


    You need at least the following to be met if you are going to adapt the code I gave you:

    • Each cell on a single row (could be a hidden row) needs to have a value, preferably numeric, that can be evaluated just as is done for column-C for hiding/unhiding rows
    • The input cell used to trigger the code for hiding/unhiding columns cannot be included in the range of columns that will be hidden.
  • Re: Hide Or Filter Rows Based On Cell Value


    Oh right....that trigger part about P8 makes complete sense. I moved where the teacher enters the number of assessments.


    I did not understand the rest of what you said. Plus, I need to know how to add it on to the code. Since I left off with c8 (for period 8), does the column hiding begin with c9?


    I have attached a sample of the layout with 2 units and 3 periods. After I am all done, columns A, D, F, J, N, R, W, AA, AE, AI, and AM will be permanently hidden, so it is not so overwhelming to look at. What I need is for the number of assessments (entered in T6 for unit 1 and A06 for unit 2)to hide the superfluous assessment tables.


    As I have only programmed room for 4 assessments, it is not such a big deal for the teacher to see the excess, but on the exit card sheet, there is room for 10 exit cards, and I would like to hide the columns they do not need to see.


    Here is the sample layout containing TWO units. My spreadsheet has 5 units and 8 periods on it normally.


    MODIFICATION: Oh and I realized that I need to have a numeric value entered into all cells on the row labeling the assessments, and I have done that. It just isn't on the sample.

  • Re: Hide Or Filter Rows Based On Cell Value


    Your current structure is still a problem for hiding columns because your table of hyperlinks spans some of the columns that you want hidden. At least the first three assessment tables for Unit-1 would have to remain visible at all times in order to use the table of links. (BTW - none of the links are working in the sample file.)


    It would be best if you moved your "navigation table" to another worksheet. Or, at least, use only column-A and as many rows as needed to create the table of links, making sure that all of the assessment tables are below the rows used for the link table.

  • Re: Hide Or Filter Rows Based On Cell Value


    I know none of the links are working in the sample. It was just to give you an idea of the layout. The links are active on my real spreadsheet.


    And I realized the issue with the hyperlinks. I was planning on saying the first 3 have to stay. The real reason I want to hide the columns is on the exit card spreadsheet, which leaves room for 10 exit cards. THe first 3 can stay. If they only have 2, that is only looking at one extra, so it is not a big deal.


    I guess I could just use column A for the navigation bar. The reason why I have it spanning across the top is because I froze those panes, so they have the links even when they are currently viewing far down in the document.


    I thought about the hiding of the columns after I created the navigation table. I am having ideas later throughout the creation of this program, so it is causing some re-coding, but that is fine, this is a learning process for me.


    So with all that said and done, how do I append the hiding of columns to your code of hiding rows? I am unsure if I just start it with c9 and attach the code I posted earlier (which was the adaptation of your code), or if the code I posted earlier is right or not?


    And do you think it would be better if I just put the navigation table in column A?

  • Re: Hide Or Filter Rows Based On Cell Value


    Here is the code modified to include hiding columns


    Quote

    And do you think it would be better if I just put the navigation table in column A?


    Since this is a work in progress and subject to change based on your learning/developing experience, it is entirely up to you. However, you can improve the navigation, as shown in the attachment, by using a data validation list, a forms button, a bit of VBA using the Select Case method to go to the desired range. There are other ways to do this, such as using custom views.

  • Re: Hide Or Filter Rows Based On Cell Value


    CONCERNING THE NAVIGATION BAR:


    That is a wonderful idea, and I had thought of it, but I ran into a problem. The name of the units will be up to the teachers. So I can't just say if Case "Unit 1" in the code because it won't stay named Unit 1. The teacher will enter in the unit name.


    Initially I was going to have the teachers enter in the data in the sample page I showed you, but now I am creating a set-up worksheet.


    Is there a way to reference the Case name to a cell. In my set-up page (sheet 2) in cell A3 the teacher will enter the name of Unit 1. Right now it just says Unit 1, but it will be changed. So in the VBA coding can I reference worksheet(sheet2).Range(A3) as the case? Or somehow reference the first selection in the dropdown as the case.


    The data validation will be referencing the named range A3:A7 (units). But like I said the names entered in A3:A7 will change.


    The period names will also change as elementary teachers do not have periods, but rather subjects, so they will change it to English, Math etc......


    This is why I had decided to do the less-attractive and more tedious method of hyperlinks because the changing of names did not affect the functionality of the hyperlinks.


    However, I would much rather do the data validation and button method. Is this possible?



    CONCERNING THE HIDING OF ROWS AND COLUMNS:


    Since I am now using this set-up, I have reworked a few things, and I would like the hidden rows to be based on a cell in another worksheet.


    I have created a worksheet that is the set-up page for the teacher, and it includes entering in the number of students per period.


    I tried to modify the code like this:




    But it didn't work. To make it easier for the teachers, I just wanted them to enter all their set-up data in one place.


    The setrng is all referring to sheet 1, but I need the trigger cell to be on sheet2.

  • Re: Hide Or Filter Rows Based On Cell Value


    So, I am really trying to solve my conflicts myself, but I have stared at this code for a LONG time, and I can not find the error.


    Here is the code for the hiding the rows and columns, and whenever I enter a number into any of the trigger cells the following error message comes up: "Run-time error '438' object doesn't support the...." However, if I press end on the message it will still hide the rows according to the value entered in any of the period triggers.


    And it will hide the columns for the unit 1 trigger, but it will not hide the columns for unit 2-5 trigger. When I pressed debug, it highlighted each of this line in the unit2- unit5 range: c10.EntireColumn.Hidden = False. c11, c12, and c13 were all highlighted.



    This is the code (I skipped c1-c7 so you did not have to look at such a long code):


  • Re: Hide Or Filter Rows Based On Cell Value


    How you setup the navigation of your workbook/worksheets is a question unrelated to the topic of your thread title. Per the forum rules you will need to ask questions on this in a new thread.

    Quote

    CONCERNING THE HIDING OF ROWS AND COLUMNS:


    Since I am now using this set-up, I have reworked a few things, and I would like the hidden rows to be based on a cell in another worksheet.


    I have created a worksheet that is the set-up page for the teacher, and it includes entering in the number of students per period.


    With this change in structure, sheet2 (or whatever sheet it is) now becomes the sheet in which the event to trigger the code must occur. Thus the code will need to reside in the module for sheet2, with applicable revision:


    Quote

    And it will hide the columns for the unit 1 trigger, but it will not hide the columns for unit 2-5 trigger. When I pressed debug, it highlighted each of this line in the unit2- unit5 range: c10.EntireColumn.Hidden = False. c11, c12, and c13 were all highlighted.


    Check your variable references. You have a mismatch here:

  • Re: Hide Or Filter Rows Based On Cell Value


    I changed A0 to AO, but it still is not working. The debug is highlighting the c11 code line.

Participate now!

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