Overflow error

zakynthos

Board Regular
Joined
Mar 28, 2011
Messages
169
Hi,

I'm taking a course on VBA and have tried out the following code for the 'find' function, ie to find and replace occurrences of 'dog' with 'dog found'

I'm getting an error message about 'overflow' but I believe this relates to "assignment, calculation, or data type conversion is too large to be represented within the range of values allowed for that type of variable." But I'm just trying to 'find' dog - that's only 3 letters so this error message must relate to another part of the code.

Anyway, here it is - can anyone offer a reason for the error? Als, I've removed the 'matchcase:=matchcase' which occurred after SearchDirection:=xlNext because that also resulted in an error message 'variable not defined':


Sub macro1()

Dim result As Range
Dim searchterm As String
searchterm = "dog"


ActiveSheet.Select

Do

With ActiveSheet.Cells

Set result = .find(What:=searchterm, After:=.Cells(.Cells.Count), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)

result.Select

'change value so it won't find cell again
ActiveCell.Value = ActiveCell.Value & " ##found##"
Set result = .FindNext(result)
End With

Loop Until result Is Nothing

End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try removing the part in red

Rich (BB code):
Set result = .find(What:=searchterm, After:=.Cells(.Cells.Count),  LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows,  SearchDirection:=xlNext)
 
Upvote 0

Forum statistics

Threads
1,224,536
Messages
6,179,402
Members
452,909
Latest member
VickiS

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