View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Charley Kyd[_2_] Charley Kyd[_2_] is offline
external usenet poster
 
Posts: 30
Default Defining a discontiguous Range object

Thanks, Jim.

Charley
"Jim Cone" wrote in message
...
Charley,

Loops are a very useful tool and easy to write.
If written properly they will execute very fast.
With that said, code similar to the following will reduce the
searching/looping significantly...
'----------------------------------------------------------------
Set FirstRng = MyColumn.SpecialCells(xlCellTypeFormulas)
Set SecondRng = MyColumn.SpecialCells(xlCellTypeConstants)
'Union method generates an error if a range is nothing
If FirstRng Is Nothing Then
Set FirstRng = SecondRng
ElseIf SecondRng Is Nothing Then
Set SecondRng = FirstRng
End If
Set FinalRange = Application.Union(FirstRng, SecondRng)
'---------------------------------------------------------------
Now run your loop thru "FinalRange"

Regards,
Jim Cone
San Francisco, CA
====================================

"Charley Kyd" wrote in message
...
Jim,

Unless I'm missing something, I don't think SpecialCells will do what I
want, without looping.

If someone didn't offer a better solution, I had thought about looping
through the data once, hiding each row that I don't want in my Range

object,
and then using SpecialCells to return the discontiguous range of the
unhidden cells that I do want. That solution would be rather fast to

code
and fast to execute. But I was hoping for something more direct.

Any other ideas?

Charley
"Jim Cone" wrote in message
...
Charley,

Take a look at the "SpecialCells" method in ExcelVB help.
It does what you want, except for picking out particular values.

Regards,
Jim Cone
San Francisco, CA

- snip -