Hoping someone may be able to identify what I am doing wrong. I've written VBA to hide/unhide rows based on values in multiple cells when button is clicked, but it's only working on the value in the first cell and not the full range.
My file starts with rows 15:31 hidden. The user is asked to submit their rating from 1 to 5 on rows 6:14 which the result feeds into column A of respective row, hence the case values in the code. If any of the users ratings are less than 4, then rows 15:31 should remain hidden. If they are all 4 or over, then rows 15:22 should unhide. The user then rates themselves from 1 to 5 again on rows 15:22 and if their ratings are less than 4, rows 23:31 remain hidden but if they are all 4 or over, then rows 23:31 will unhide.
Here is my code:-
Sub Submit()
Select Case Range("A6,A7,A8,A9,A10,A11,A12,A13,A14")
Case Is >= 4: Rows("15:22").EntireRow.Hidden = False
Worksheets("Print Result - Foundation").Visible = False
Select Case Range("A15,A16,A17,A18,A19,A20,A21,A22")
Case Is >= 4: Rows("23:31").EntireRow.Hidden = False
Worksheets("Print Result - Grow").Visible = False
Case Is < 4: Rows("23:31").EntireRow.Hidden = True
End Select
Case Is < 4: Rows("15:31").EntireRow.Hidden = True
End Select
End Sub
The above works well and hides rows 15:31 when A6 is less than 4 but when A7:A14 is less than 4, it displays rows 15:22. And the same with the second range, when A15 is less than 4 rows 23:31 are hidden but when A16:A22 are less than 4, rows 23:31 are displaying.
I have also tried entering the range as ("A6:A14") and ("A15:A22") but when I try to run the macro, it returns a run-time error '13': Type mismatch.
Can anyone see where I have gone wrong?
select caseonly evaluates the first cell (A6). What do you want to achieve: if any of the cells is >=4?Case Is >= 4- did you mean that all of those cells are>= 4, or any one of them is>= 4, or theSUMtotal of those cells>= 4?