I am looking through selection areas (one or more ranges) and I also tried looking at each cell in a range to see if any cells are hidden.
In my case, I expect entire rows to be hidden, but still, they're just subsets of selected areas.
No matter if I look at a range or a cell (still a range of one cell) I get Run-time error '1004': Unable to GET the Hidden property of the Range class.
VBA help says '.Hidden' can be set or it returns a "varient", so I'm just trying to see if anything is hidden. In the spreadsheet I hide column B and C, and then select cells in one row from column A to column F and run the macro and get the 1004 error. Even if no columns are hidden I get the same 1004 error.
Here is the code snippet:
Dim hiddenCellsExist As Variant ' I also tried Boolean to no avail.
hiddenCellsExist = False
MsgBox "hiddenCellsExist = " & hiddenCellsExist ' This tells me "hiddenCellsExist = False
For Each rngPart In Application.Selection.Areas
' MsgBox rngPart.Address ' If I uncomment this it tells me the range. A$119:E$119 if B and C are hidden or not.
hiddenCellsExist = rngPart.Hidden ' The 1004 error appears here.
MsgBox "hiddenCellsExist = " & hiddenCellsExist ' The code doesn't get here.
Exit Sub ' Because I'm testing the code I exit.
All the other Q&As are about setting or unsetting the hidden property and most of the solutions are about unprotecting the worksheet/book, but mine is not protected and I'm not setting anything at this part in the code.
What am I doing wrong? (I get the same error if I use an inner loop looking at each cell in each range.)