Forum Discussion
Hide rows in a different sheet based on a value (that contains specific letters)
"ma" occurs in D9 and D10. Doesn't that cause confusion?
Let's say to use wo from woman as I will not have any duplications in the original file.
- HansVogelaarJul 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.