Thread
:
Intersect Function Problem
View Single Post
#
2
Posted to microsoft.public.excel.programming
Die_Another_Day
external usenet poster
Posts: 644
Intersect Function Problem
Kathy, from what I can tell you are passing a range to this function,
then changing sheets and asking for an intersect. From what I
understand from Tom, Range is an object and must have a parent object,
which is the Sheet on which the Range resides, so in affect, you are
asking for the Intersection of the original sheet, and the second sheet
which does not exist. Perhaps you could look for the intersection of
Range(x.Address).
HTH
Charles Chickering
wrote:
I'm trying to run this function but I'm getting an error witht the
Intersect function for my second worksheet. Any idea why?!
Function SelectRangeToChange(X As Range, ToFind1 As String, ToFind2 As
String, TabNum As Variant) As Range
Dim Selection As Range, Cell As Range, ToChange1 As Range,
ToChange2 As Range, ToChange3 As Range
For i = 1 To TabNum Step 1
Worksheets(i).Select
Set Selection = Intersect(X, ActiveSheet.UsedRange)
***************PROBLEM******
For Each Cell In Selection
If (((Cell.Value) = ToFind1) Or (InStr(1, Cell.Value,
ToFind1, vbTextCompare))) Then
If ToChange1 Is Nothing Then
Set ToChange1 = Cell
Else: Set ToChange1 = Union(ToChange1, Cell)
End If
ElseIf (((Cell.Value) = ToFind2) Or (InStr(1, Cell.Value,
ToFind2, vbTextCompare))) Then
If ToChange2 Is Nothing Then
Set ToChange2 = Cell
Else: Set ToChange2 = Union(ToChange2, Cell)
End If
Else
If ToChange3 Is Nothing Then
Set ToChange3 = Cell
Else: Set ToChange3 = Union(ToChange3, Cell)
End If
End If
Next Cell
Next i
End Function
Thanks,
Reply With Quote
Die_Another_Day
View Public Profile
Find all posts by Die_Another_Day