Thread: SpecialCells
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default SpecialCells

If you read Chips example at

http://www.cpearson.com/excel/cells.htm

he notes that
Range("A1:B2")(5) refers to Cell A3, Range("A1:B2")(14) refers to Cell B7,
etc.

Notice that there are not 5 cells in A1:B2, yet you can still reference cell
A3.

This is a guess, but your range is comprised of several areas. Since you
don't explicitly state the area, the macro assumes the first area. When the
counter variable exceeds the number of cells in the first area, it runs over
to the hidden cells. Maybe you can loop through the areas then the cells??

for i = 1 to rng1.areas.count
for t = 1 to rng1.areas(i).cells.count
rng1.areas(i).cells(t)



"mike" wrote:

I am trying to access the next cell in a Range of SpecialCells of xlVisible
type only. For some reason when I use
Dim r as Range, rng1 as range
set rng1 = colums(3).SpecialCells(xlVisible)
For each r in rng1
blah,blah
Next
It goes through the visible cells. BUT when I replace the For Each loop with

rng1.Cells(2,1).Value
rng1.Cells(3,1).Value

where cells(3,1,) in the normal worksheet is hidden, it will return the
hidden cell(the hidden cell right after the non-hidden cell cells(2,1)
instead of returning the next visible cell in the rng1 object.
Any ideas? I want to compare the contents of two visible cells to see if
they are duplicates, and delete the second cell and the hidden cells after
the duplicate.