Error reading range

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,097
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
VBA Code:
Look = xlComments
SearchPart = xlPart
rCol= "C2:C58"
Set Found = Range(rCol).Find(What:=TextBox1.Text, lookIn:=Look, Lookat:=SearchPart)
If Not Found Is Nothing Then
    Set FirstFound = Found
    Do
        Debug.Print Found, Found.Address
        Set Found = Range(rCol).FindNext(After:=Found)
    Loop Until FirstFound.Address = Found.Address
End If
The last address it prints is C59. That's one more than the range should have and I get error
Run-time error '1004':
Unable to get the FindNext property of the Range class


But if rCol is "C:C" there is no error.
Is how I'm defining the rows or range wrong?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Change this line:

VBA Code:
Loop Until FirstFound.Address = Found.Address

For this:

VBA Code:
Loop Until FirstFound.Address = Found.Address Or Intersect(Range(rCol), Found) Is Nothing
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

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