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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,873
Messages
6,122,029
Members
449,061
Latest member
TheRealJoaquin

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