engrwanabe
04-24-2008, 03:48 PM
I am trying to create a script that will allow the user to search for a string and then based on the search results it will select all of the cells that found the string inside of it. I figured that a union of ranges would help me with this but I can not figure out what I am doing wrong. Could someone please help. here is the code that I have so far:
<code>
With Rng1
Set Cell = .Find(text)
If Not Cell Is Nothing Then
Set MyRange = Range(Cell.Address)
InitAddress = Cell.Address
End If
Set Cell = .FindNext(Cell)
While Not InitAddress = Cell.Address
If MyRange Is Nothing Then
Set MyRange = Range(Cell.Address)
Else
Set MyRange = Application.Union(MyRange, Range(Cell.Address))
End If
Set Cell = .FindNext(Cell)
Wend
End If
End With
MyRange.CurrentRegion.Select
</code>
<code>
With Rng1
Set Cell = .Find(text)
If Not Cell Is Nothing Then
Set MyRange = Range(Cell.Address)
InitAddress = Cell.Address
End If
Set Cell = .FindNext(Cell)
While Not InitAddress = Cell.Address
If MyRange Is Nothing Then
Set MyRange = Range(Cell.Address)
Else
Set MyRange = Application.Union(MyRange, Range(Cell.Address))
End If
Set Cell = .FindNext(Cell)
Wend
End If
End With
MyRange.CurrentRegion.Select
</code>