Code works or throws error sometimes

szymagic

Board Regular
Joined
Jul 8, 2016
Messages
61
Hello all,

I've been trying to figure this out for a while now (I hope it is right in front of my face and I just can't see it).


I have a line of code that works when it is ran in its sub, but throws an error when that sub is called upon.

I get a "Run-time error '1004': Application-defined or object-defined error"

This is the line

Code:
nRow = Sheets("Base").Range(Sheets("Base").Cells(xRow - 5, 9), Sheets("Base").Cells(xRow + 4000, 9)).Find(upname).Row

nRow and xRow are Longs and upname is a variant

I originally got this error with this line:

Code:
nRow = Sheets("Base").Range(Cells(xRow - 5, 9), Cells(xRow + 4000, 9)).Find(upname).Row

and "fixed" it by adding the more defined Sheets("Base").

It worked for a while, but when I called the macro it threw the above error. Any ideas? Thanks in advance!!
 
Figured it out! Sorry to waste anybody's time, and the fourm's space!

If anyone is curious, xRow was less than 5 so the could would produce a negative row value!

Thanks!
 
Upvote 0
Put msgbox xRow just before the line runs. I suspect its nothing...
 
Upvote 0

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