R
rick
With the following code, it finds the text, "red time" and
then correctly pastes the whole selection on the sheet
named "found". But I have this within a loop, and if the
text is not found, then different text is pasted in the
A4250 area, and it is to try another find on that text.
If the text is found on the first time thru the loop, it
works correctly, pasting the selection on the "found"
sheet.... and continues on thru the loop, looking at each
successive pieces of text, and (correctly) NOT finding "red
time" in any of the successive ones, it completes the loop
without any errors given.
If the text is NOT found on the FIRST time thru the
loop, it gives this error:
"Object variable or With block variable not set", and it
hilites this:
If .Find(What:="red time", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate Then
--------------------------------------------
Range("A4250").Select
With Selection
If .Find(What:="red time", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate Then
Selection.Copy
Sheets("found").Select
Range("A4250").Select
ActiveSheet.Paste
Else
End If
End With
then correctly pastes the whole selection on the sheet
named "found". But I have this within a loop, and if the
text is not found, then different text is pasted in the
A4250 area, and it is to try another find on that text.
If the text is found on the first time thru the loop, it
works correctly, pasting the selection on the "found"
sheet.... and continues on thru the loop, looking at each
successive pieces of text, and (correctly) NOT finding "red
time" in any of the successive ones, it completes the loop
without any errors given.
If the text is NOT found on the FIRST time thru the
loop, it gives this error:
"Object variable or With block variable not set", and it
hilites this:
If .Find(What:="red time", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate Then
--------------------------------------------
Range("A4250").Select
With Selection
If .Find(What:="red time", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate Then
Selection.Copy
Sheets("found").Select
Range("A4250").Select
ActiveSheet.Paste
Else
End If
End With