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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,713
Messages
5,833,269
Members
430,200
Latest member
ADLHMA2022

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
Top