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:eek:ffice:eek:ffice" /><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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

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