Forum Discussion
Steiny88
Jul 24, 2022Copper Contributor
Hide rows in a different sheet based on a value (that contains specific letters)
I have 2 sheets and attached an example: Sheet1 D8 has Baby as value Sheet1 D9 has Man as value Sheet1 D10 has Woman as value The code to search for "ab" in column D and if it finds it somewh...
Steiny88
Jul 24, 2022Copper Contributor
I didn't realize that 😄
Let's say to use wo from woman as I will not have any duplications in the original file.
Let's say to use wo from woman as I will not have any duplications in the original file.
HansVogelaar
Jul 24, 2022MVP
See the attached workbook. It is now a macro-enabled workbook (*.xlsm) so you'll have to allow macros when you open it.
To view the code, right-click the sheet tab of Sheet1 and select 'View Code' from the context menu.
- Steiny88Jul 24, 2022Copper ContributorThat works perfectly.
I have one more question. In the code I cannot see which rows to hide as in my original file I need to hide for example Row 8 and then Row 19 then Row 32 but in the code I don't understand how it knows which row to hide. If there is ab to select which exact rows to hide - for example for ab to hide row 8 and 19, how can I do that in the code?
Thanks a lot!- HansVogelaarJul 24, 2022MVP
The code is the Worksheet_Change event procedure of Sheet1. It runs automatically when you change the value of one or more cells on Sheet1.
The code first checks whether the changed cell is in column D.
If so, it unhides the corresponding row on Sheet2, then checks the new value of the cell. If it contains "ab, "ma" or "om", it hides the corresponding row on Sheet2, otherwise it leaves it visible.
Since the code reacts to you changing a cell, it "knows" which row to hide/unhide on Sheet2: the row with the same number.
- Steiny88Jul 24, 2022Copper ContributorYes, that's what I want to fix, if it sees ab to hide for example 2 rows which are not corresponding to the rows where this ab is located on sheet1. If in D8 I write Baby, to hide for example 2 entirely different rows like 19 and 32.