AndrewCrosby
New Member
- Joined
- Jan 23, 2014
- Messages
- 3
Hi,
I've been encountering a problem with hiding EntireRow and EntireColumn. I've constructed a basic demo, the spreadsheet looks like this with 2 named ranges:
My worksheet
My code
In my code I have two Subroutines, which loop through the named ranges and hide columns:
My problem
However they do not work reliably. Initially they work and will hide any columns/rows where the cell value is greater than 5, but then they stop working.
Currently:
when I run HideColumns and view the Immediate window it records this:
So it loops through all the columns in the myCol range. And it does hide any column where the value is greater than 5. This is what I want.
However, when I run HideRows and view the Immediate window it records this:
So it seems to fall out of the loop after the first iteration. It does not record any error message.
Can any one advise what I am doing wrong? I have tried using full qualified range references (ie Sheets("Sheet1").Range("myRows") and Sheets("Sheet1").Range("myCols")) but they stop working too.
Microsoft Office Professional Plus 2010
Version 14.0.7106.5003
Thanks
Andrew
I've been encountering a problem with hiding EntireRow and EntireColumn. I've constructed a basic demo, the spreadsheet looks like this with 2 named ranges:
My worksheet
My code
In my code I have two Subroutines, which loop through the named ranges and hide columns:
Code:
Option Explicit
Private Sub HideColumns()
Dim myCell As Range
For Each myCell In Range("mycols").Cells
Debug.Print myCell.Value
myCell.EntireColumn.Hidden = (myCell.Value > 5)
Next
End Sub
Private Sub HideRows()
Dim myCell As Range
For Each myCell In Range("myRows").Cells
Debug.Print myCell.Value
myCell.EntireRow.Hidden = (myCell.Value > 5)
Next
End Sub
My problem
However they do not work reliably. Initially they work and will hide any columns/rows where the cell value is greater than 5, but then they stop working.
Currently:
when I run HideColumns and view the Immediate window it records this:
Code:
[COLOR=#333333][FONT=Segoe UI]
1
2
3
4
5
6
7
8
9
10
[/FONT][/COLOR]
So it loops through all the columns in the myCol range. And it does hide any column where the value is greater than 5. This is what I want.
However, when I run HideRows and view the Immediate window it records this:
Code:
[COLOR=#333333][FONT=Segoe UI]
1
[/FONT][/COLOR]
So it seems to fall out of the loop after the first iteration. It does not record any error message.
Can any one advise what I am doing wrong? I have tried using full qualified range references (ie Sheets("Sheet1").Range("myRows") and Sheets("Sheet1").Range("myCols")) but they stop working too.
Microsoft Office Professional Plus 2010
Version 14.0.7106.5003
Thanks
Andrew