select.find ERROR

cirugio

Board Regular
Joined
Mar 30, 2010
Messages
130
Hoping someone can assist. I currently have a module with a procedure which contains a Selection.Find command. I just use it to look up a value ("e-mail") and then replace contents of cells to the right of it using the offset command.
For some reason, I keep getting the following error "Object variable or With block variable not set" on the
Selection.Find... line. Anyone have thoughts on this? Thanks.


Sub ClearEmail()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Columns("A:A").Select<o:p></o:p>
Range("A1").Activate<o:p></o:p>
ActiveCell.Select<o:p></o:p>
<o:p></o:p>
Selection.Find(What:="e-mail", After:=ActiveCell, LookIn:=xlFormulas, LookAt _<o:p></o:p>
:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _<o:p></o:p>
False).Activate<o:p></o:p>
<o:p></o:p>
ActiveCell.Offset(0, 7) = "------------"<o:p></o:p>
ActiveCell.Offset(0, 8) = "------------"<o:p></o:p>
ActiveCell.Offset(0, 9) = "------------"<o:p></o:p>
ActiveCell.Offset(0, 10) = "------------"<o:p></o:p>
ActiveCell.Offset(0, 11) = "------------"<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try like this

Code:
Sub ClearEmail()
Dim Found As Range
Set Found = Columns("A").Find(What:="e-mail", LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False)
If Not Found Is Nothing Then Found.Offset(, 7).Resize(, 5).Value = "------------"
End Sub
 
Upvote 0
Try this, which checks if what you are looking for is found before continuing.
Code:
Option Explicit
 
Sub ClearEmail()
Dim rngFnd As Range
Dim strLook As String
 
    strLook = "email"
 
    Set rngFnd = Range("A:A").Find(strLook)
 
    If rngFnd Is Nothing Then
        MsgBox "Not found"
    Else
        rngFnd.Offset(, 7).Resize(, 5) = "-------"
    End If
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top