LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Increment cells only in filtered range?

This macro is supposed to increment down to the next visible cell in a
filtered range, then to the first empty cell below the filtered range. It's
based off code Tom Ogilvy gave me, but I must have changed something and I
can't find it. I call this macro within the loop of another macro. The
problem is that this doesn't stop when it hits the end of the filtered
range; instead, it loops back up to Row 1.



When stepping through, when the ActiveCell is in the last visible row of the
filtered range, on the third "Set rng =" line, "rng.count" is one more than
the row number of the ActiveCell. But when I step down to the next line
("On Error Resume Next"), I moused over rng.count and found it was 1. (I
don't understand what this "count" is counting - rows? cells? something
else?)



What I expected was the ActiveCell to become the first empty cell below the
filtered range. The calling macro then would detect the empty cell and end
its loop. What happens, though, is this macro selects back up to the top
left cell ("rng1(1).Select"), and never goes below the filtered range,
creating an endless loop.



How do I fix this to drop out of the filtered range?

Ed



Sub Increment1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1(1).Select
End If
End Sub




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
calculate values in an unlimited range of cells in a column WITHOUTalso calculating values that had previously been filtered AGAINST? yadang Excel Discussion (Misc queries) 2 October 1st 09 06:18 PM
Count only cells within Filtered Range Corey Excel Worksheet Functions 5 January 26th 09 10:02 PM
sum of visable cells in filtered range RHino56 Excel Worksheet Functions 7 June 1st 08 10:13 PM
average of visible cells in a filtered range dave roth Excel Worksheet Functions 5 May 23rd 05 12:56 PM
Cells.Find in Auto-Filtered range mark Excel Programming 2 September 16th 03 11:55 PM


All times are GMT +1. The time now is 03:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"