Find and Replace - Error 91

SanguineSleet

New Member
Joined
Aug 10, 2018
Messages
5
Hi there,

I am running a find and search function on a column of data on a simple Macro I have created. However I seemed to be getting error 91 when it is encountering data that it cannot find.

My current code is:

Range("I:I").Select
Columns("I:I").Select
Selection.Find(What:="1", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Selection.Replace What:="1", Replacement:="Revocable", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Columns("I:I").Select
Selection.Find(What:="2", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Selection.Replace What:="2", Replacement:="Irrevocable", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

However when I have data that does not have "2" in the I column it will stop and error.

Any help would be greatly appreciated!
Thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi & welcome to the board
Will you only ever have a maximum of one "1" & one "2" in col I?
 
Last edited:
Upvote 0
Hi & welcome to the board
Will you only ever have a maximum of one "1" & one "2" in col I?

Hi Fluff,

That is correct its our work systems and it uses numbers instead of words. The only options are 1 and 2. However I have found some raw data that only has 1 and when I try running it I get the error.
 
Upvote 0
In that case do you want to replace all 1s & all 2s, or only the first of each?
 
Upvote 0
In that case try
Code:
Sub Myreplace()
   With Range("I:I")
      .Replace 1, "Revocable", xlWhole, , , , False, False
      .Replace 2, "Irrevocable", xlWhole, , , , False, False
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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