PC Review


Reply
Thread Tools Rate Thread

Autofiltered cells not "Hidden"

 
 
Lionel H
Guest
Posts: n/a
 
      11th Jul 2008
Having selected a number of cells, I use the following to process them:

Sub Demo1()
Dim myCell
For Each myCell In Selection
‘Do some processing:
Debug.Print myCell.Value
Next myCell
End Sub

This works fine until I select cells across cells hidden by the autofilter
The above macro includes the cells hidden by the autofilter which I do not
want.
I amend my code as follows:

Sub Demo2()
Dim myCell
For Each myCell In Selection
If Not myCell.Hidden Then ‘this line fails – 1004 Unable to get the
Hidden property of the range class
‘Do some processing:
Debug.Print myCell.Value
End If
Next myCell
End Sub

I have used debug watch on myCell and Selection and cannot find an
alternative way of skipping the autofiltered cells.
Can anyone help please?

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      11th Jul 2008
if mycell.entirerow.hidden = false then
'do your stuff
...
end if

Or you could look at just the visible cells in the selection

dim vRng as range
set vrng = nothing
on error resume next
set vrng = intersect(selection,selection.cells.specialcells(xlcelltypevisible)
on error goto 0

if vrng is nothing then
'no cells are visible!
else
for each mycell in vrng.cells
'do something
next mycell
end if

Lionel H wrote:
>
> Having selected a number of cells, I use the following to process them:
>
> Sub Demo1()
> Dim myCell
> For Each myCell In Selection
> ‘Do some processing:
> Debug.Print myCell.Value
> Next myCell
> End Sub
>
> This works fine until I select cells across cells hidden by the autofilter
> The above macro includes the cells hidden by the autofilter which I do not
> want.
> I amend my code as follows:
>
> Sub Demo2()
> Dim myCell
> For Each myCell In Selection
> If Not myCell.Hidden Then ‘this line fails – 1004 Unable to get the
> Hidden property of the range class
> ‘Do some processing:
> Debug.Print myCell.Value
> End If
> Next myCell
> End Sub
>
> I have used debug watch on myCell and Selection and cannot find an
> alternative way of skipping the autofiltered cells.
> Can anyone help please?


--

Dave Peterson
 
Reply With Quote
 
Mike H.
Guest
Posts: n/a
 
      11th Jul 2008
Someone else came up with this which should work:

Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1

For i = 1 To nLastRow
If Cells(i, "A").EntireRow.Hidden Then
Else
'perform your task!
End If
Next


 
Reply With Quote
 
Lionel H
Guest
Posts: n/a
 
      14th Jul 2008
Dave,
Thanks for the reply.
your first offering works, is simplest and therefore the best.
I thought I had tried this but looking back through my tests,
I find I had used:
If not selection.entirerow.hidden then
DOH!
Thanks again.
Lionel

"Dave Peterson" wrote:

> if mycell.entirerow.hidden = false then
> 'do your stuff
> ...
> end if
>
> Or you could look at just the visible cells in the selection
>
> dim vRng as range
> set vrng = nothing
> on error resume next
> set vrng = intersect(selection,selection.cells.specialcells(xlcelltypevisible)
> on error goto 0
>
> if vrng is nothing then
> 'no cells are visible!
> else
> for each mycell in vrng.cells
> 'do something
> next mycell
> end if
>
> Lionel H wrote:
> >
> > Having selected a number of cells, I use the following to process them:
> >
> > Sub Demo1()
> > Dim myCell
> > For Each myCell In Selection
> > ‘Do some processing:
> > Debug.Print myCell.Value
> > Next myCell
> > End Sub
> >
> > This works fine until I select cells across cells hidden by the autofilter
> > The above macro includes the cells hidden by the autofilter which I do not
> > want.
> > I amend my code as follows:
> >
> > Sub Demo2()
> > Dim myCell
> > For Each myCell In Selection
> > If Not myCell.Hidden Then ‘this line fails – 1004 Unable to get the
> > Hidden property of the range class
> > ‘Do some processing:
> > Debug.Print myCell.Value
> > End If
> > Next myCell
> > End Sub
> >
> > I have used debug watch on myCell and Selection and cannot find an
> > alternative way of skipping the autofiltered cells.
> > Can anyone help please?

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Lionel H
Guest
Posts: n/a
 
      14th Jul 2008
Mike,
Deve Peterson got there first, so I used his solution, but thanks for the
response anyway.
(See also my reply to Dave!)
regards,
Lionel

"Mike H." wrote:

> Someone else came up with this which should work:
>
> Set r = ActiveSheet.UsedRange
> nLastRow = r.Rows.Count + r.Row - 1
>
> For i = 1 To nLastRow
> If Cells(i, "A").EntireRow.Hidden Then
> Else
> 'perform your task!
> End If
> Next
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Jul 2008
That first suggestion may be the easiest to type, but it could take the longest
to run.

If you have 65k rows of info and only the 2nd and 65kth row are visible, why
check each of them.


Lionel H wrote:
>
> Dave,
> Thanks for the reply.
> your first offering works, is simplest and therefore the best.
> I thought I had tried this but looking back through my tests,
> I find I had used:
> If not selection.entirerow.hidden then
> DOH!
> Thanks again.
> Lionel
>
> "Dave Peterson" wrote:
>
> > if mycell.entirerow.hidden = false then
> > 'do your stuff
> > ...
> > end if
> >
> > Or you could look at just the visible cells in the selection
> >
> > dim vRng as range
> > set vrng = nothing
> > on error resume next
> > set vrng = intersect(selection,selection.cells.specialcells(xlcelltypevisible)
> > on error goto 0
> >
> > if vrng is nothing then
> > 'no cells are visible!
> > else
> > for each mycell in vrng.cells
> > 'do something
> > next mycell
> > end if
> >
> > Lionel H wrote:
> > >
> > > Having selected a number of cells, I use the following to process them:
> > >
> > > Sub Demo1()
> > > Dim myCell
> > > For Each myCell In Selection
> > > ‘Do some processing:
> > > Debug.Print myCell.Value
> > > Next myCell
> > > End Sub
> > >
> > > This works fine until I select cells across cells hidden by the autofilter
> > > The above macro includes the cells hidden by the autofilter which I do not
> > > want.
> > > I amend my code as follows:
> > >
> > > Sub Demo2()
> > > Dim myCell
> > > For Each myCell In Selection
> > > If Not myCell.Hidden Then ‘this line fails – 1004 Unable to get the
> > > Hidden property of the range class
> > > ‘Do some processing:
> > > Debug.Print myCell.Value
> > > End If
> > > Next myCell
> > > End Sub
> > >
> > > I have used debug watch on myCell and Selection and cannot find an
> > > alternative way of skipping the autofiltered cells.
> > > Can anyone help please?

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulty "countif"-ing number of "L1" or "L2" on an autofiltered pmdoherty Microsoft Excel Worksheet Functions 4 6th Feb 2009 11:23 AM
"ignoring" hidden cells in a copy/paste operation =?Utf-8?B?Z3Zt?= Microsoft Excel Misc 2 22nd Mar 2007 10:38 PM
Hi-Lite "empty" unlocked cells in non-hidden rows =?Utf-8?B?QkVFSkFZ?= Microsoft Excel Programming 4 14th Mar 2007 11:44 AM
How to only "paste values" of cells that are not "hidden"? Danny Microsoft Excel Misc 2 18th Jul 2005 12:46 AM
Enter a "checkmark" in an AutoFiltered cell L Mehl Microsoft Excel Programming 2 27th Sep 2004 12:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 AM.