Forum Discussion
VBA to hide rows based on value in cell (multiple criteria)
Hello all,
I've made a summary sheet of a questionnaire in a workbook. Not all questions have to be answered, and I'm trying to make a macro that would automatically hide rows of the questions that do not have an answer.
https://icrc-my.sharepoint.com/:x:/g/personal/mvanbuuren_icrc_org/ESgikmfBXIZLgX1qA_yng6AB20WcbY5H6rSjL2G85YeSww?e=y1QVuL
I've found some VBAs but they only look at one criteria per cell. I'd need one that would hide a row if the value in the cell in column C is not 1, 2 or 3. Would anyone be able to help?
3 Replies
Right-click the sheet tab.
Select 'View Code' from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Activate() Intersect(Range("C:C"), Me.UsedRange).AutoFilter Field:=1, Criteria1:="<>" End Sub
Switch back to Excel.
Save the workbook as a macro-enabled workbook (*.xlsm).
Make sure that you allow macros when you open it.
The filter will be updated automatically when you activate the Resumen sheet.
- Marieke1405Copper ContributorThanks very much! Apologies for the late reply, I've tried the code but it doesn't seem to be working. Not sure what the problem could be, but it's not executing.
Try the attached version. I also added a Workbook_Open event procedure to the ThisWorkbook module.
Since it is now a macro-enabled workbook (.xlsm), you'll have to allow macros when you open it.