Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default selecting a collection of cells from .Find()

I have two questions based on the following code which gives me the
collection "targetCells" where targetCells.Count can be in tens of thousands:

' start of code
Dim iSheet As Worksheet
Dim iRange As Range
Dim foundOne As Boolean
Dim firstCell As String
Set targetCells = New Collection
findValue = "xyz"
foundOne = False
For Each iSheet In ActiveWorkbook.Worksheets
Set iRange = iSheet.UsedRange
Set iCell = iRange.Find(findValue, LookIn:=xlFormulas, LookAt:=xlPart)
If Not iCell Is Nothing Then
firstCell = iCell.Address
Do
targetCells.Add iCell
foundOne = True
Set iCell = iRange.FindNext(iCell)
Loop While Not iCell Is Nothing And iCell.Address < firstCell
End If
Next
' end of code

Question #1:
How can I convert the collection "targetCells" from the following code to
XXX such that I can do XXX.Select, i.e. select these cells I've found?

Question #2:
Is there a way to modify the code above such that I can get to XXX directly
without having to arrive at targetCells first?

Thanks a lot.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default selecting a collection of cells from .Find()

You don't need the collection in making the range of all found cells unless
you need it for other purposes.

where targetCells.Count can be in tens of thousands:


If by that you mean you expect to find tens of thousands of cells and select
all, the normal simple method (below) will take a very long time if the
found cells will comprise a large number of multiple areas, ie non adjacent
cells.

Dim rMultiFound As Range
'code
'insert following in your Do loop

If rMultiFound Is Nothing Then
Set rMultiFound = iCell
Else
Set rMultiFound = Union(rMultiFound, iCell)
End If

This isn't suitable for extremely large multi areas unless you're very
patient, to do it in a time frame user a user is accustomed to expect is not
trivial. Even with other methods I wouldn't want to make a 'selection' of
8000+ areas as it becomes unstable, and would abort before making it (which
also requires working out the number of areas before making it).

Regards,
Peter T


"rockhammer" wrote in message
...
I have two questions based on the following code which gives me the
collection "targetCells" where targetCells.Count can be in tens of

thousands:

' start of code
Dim iSheet As Worksheet
Dim iRange As Range
Dim foundOne As Boolean
Dim firstCell As String
Set targetCells = New Collection
findValue = "xyz"
foundOne = False
For Each iSheet In ActiveWorkbook.Worksheets
Set iRange = iSheet.UsedRange
Set iCell = iRange.Find(findValue, LookIn:=xlFormulas, LookAt:=xlPart)
If Not iCell Is Nothing Then
firstCell = iCell.Address
Do
targetCells.Add iCell
foundOne = True
Set iCell = iRange.FindNext(iCell)
Loop While Not iCell Is Nothing And iCell.Address < firstCell
End If
Next
' end of code

Question #1:
How can I convert the collection "targetCells" from the following code to
XXX such that I can do XXX.Select, i.e. select these cells I've found?

Question #2:
Is there a way to modify the code above such that I can get to XXX

directly
without having to arrive at targetCells first?

Thanks a lot.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default selecting a collection of cells from .Find()

In addition, you have cells on multiple sheets, so you will never be able to
do xxx.select

--
Regards,
Tom Ogilvy

"rockhammer" wrote in message
...
I have two questions based on the following code which gives me the
collection "targetCells" where targetCells.Count can be in tens of
thousands:

' start of code
Dim iSheet As Worksheet
Dim iRange As Range
Dim foundOne As Boolean
Dim firstCell As String
Set targetCells = New Collection
findValue = "xyz"
foundOne = False
For Each iSheet In ActiveWorkbook.Worksheets
Set iRange = iSheet.UsedRange
Set iCell = iRange.Find(findValue, LookIn:=xlFormulas, LookAt:=xlPart)
If Not iCell Is Nothing Then
firstCell = iCell.Address
Do
targetCells.Add iCell
foundOne = True
Set iCell = iRange.FindNext(iCell)
Loop While Not iCell Is Nothing And iCell.Address < firstCell
End If
Next
' end of code

Question #1:
How can I convert the collection "targetCells" from the following code to
XXX such that I can do XXX.Select, i.e. select these cells I've found?

Question #2:
Is there a way to modify the code above such that I can get to XXX
directly
without having to arrive at targetCells first?

Thanks a lot.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default selecting a collection of cells from .Find()

Thank you, Peter T. Your suggestion worked wonderfully.
I will watch the size of the selection, and will think of a way to make
smaller selections when i hit the performance issues you noted.


"Peter T" wrote:

You don't need the collection in making the range of all found cells unless
you need it for other purposes.

where targetCells.Count can be in tens of thousands:


If by that you mean you expect to find tens of thousands of cells and select
all, the normal simple method (below) will take a very long time if the
found cells will comprise a large number of multiple areas, ie non adjacent
cells.

Dim rMultiFound As Range
'code
'insert following in your Do loop

If rMultiFound Is Nothing Then
Set rMultiFound = iCell
Else
Set rMultiFound = Union(rMultiFound, iCell)
End If

This isn't suitable for extremely large multi areas unless you're very
patient, to do it in a time frame user a user is accustomed to expect is not
trivial. Even with other methods I wouldn't want to make a 'selection' of
8000+ areas as it becomes unstable, and would abort before making it (which
also requires working out the number of areas before making it).

Regards,
Peter T


"rockhammer" wrote in message
...
I have two questions based on the following code which gives me the
collection "targetCells" where targetCells.Count can be in tens of

thousands:

' start of code
Dim iSheet As Worksheet
Dim iRange As Range
Dim foundOne As Boolean
Dim firstCell As String
Set targetCells = New Collection
findValue = "xyz"
foundOne = False
For Each iSheet In ActiveWorkbook.Worksheets
Set iRange = iSheet.UsedRange
Set iCell = iRange.Find(findValue, LookIn:=xlFormulas, LookAt:=xlPart)
If Not iCell Is Nothing Then
firstCell = iCell.Address
Do
targetCells.Add iCell
foundOne = True
Set iCell = iRange.FindNext(iCell)
Loop While Not iCell Is Nothing And iCell.Address < firstCell
End If
Next
' end of code

Question #1:
How can I convert the collection "targetCells" from the following code to
XXX such that I can do XXX.Select, i.e. select these cells I've found?

Question #2:
Is there a way to modify the code above such that I can get to XXX

directly
without having to arrive at targetCells first?

Thanks a lot.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default selecting a collection of cells from .Find()

Thanks, Tom. I will modify the code to do one sheet at a time.


"Tom Ogilvy" wrote:

In addition, you have cells on multiple sheets, so you will never be able to
do xxx.select

--
Regards,
Tom Ogilvy

"rockhammer" wrote in message
...
I have two questions based on the following code which gives me the
collection "targetCells" where targetCells.Count can be in tens of
thousands:

' start of code
Dim iSheet As Worksheet
Dim iRange As Range
Dim foundOne As Boolean
Dim firstCell As String
Set targetCells = New Collection
findValue = "xyz"
foundOne = False
For Each iSheet In ActiveWorkbook.Worksheets
Set iRange = iSheet.UsedRange
Set iCell = iRange.Find(findValue, LookIn:=xlFormulas, LookAt:=xlPart)
If Not iCell Is Nothing Then
firstCell = iCell.Address
Do
targetCells.Add iCell
foundOne = True
Set iCell = iRange.FindNext(iCell)
Loop While Not iCell Is Nothing And iCell.Address < firstCell
End If
Next
' end of code

Question #1:
How can I convert the collection "targetCells" from the following code to
XXX such that I can do XXX.Select, i.e. select these cells I've found?

Question #2:
Is there a way to modify the code above such that I can get to XXX
directly
without having to arrive at targetCells first?

Thanks a lot.




Reply
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
SUMIF on a collection of individual cells Fred Holmes Excel Worksheet Functions 9 June 23rd 09 03:40 AM
Collection from Range, tag cells on error nowon Excel Programming 1 January 3rd 06 12:34 AM
worksheets collection... find... mark kubicki Excel Programming 2 February 23rd 04 08:02 PM
Using a collection class to implement mutliple find/replace strings in cells Bill Hertzing Excel Programming 2 February 18th 04 01:42 AM
How to find the type of Sheet in Excel.Workbook.sheets collection Raj[_7_] Excel Programming 3 December 9th 03 10:48 PM


All times are GMT +1. The time now is 11:00 PM.

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"