Excel makes same error every time.

davidam

Active Member
Joined
May 28, 2010
Messages
497
Office Version
  1. 2021
Platform
  1. Windows
Hello,
I wonder if anyone has seen this before, and if they know why it happens. I am using the Offset function to return values from a list. Something like this:
Code:
name = ActiveCell.Offset((Range("A1876").Value,0).Value
Set Loc = Range ("A61501:A65500").Find(What:=name, LookIn:=xlValues)
Range("A1").Value = Loc.Offset(0,1).Value
The list is something like this:

61500 Names Top Bottom
61501 ... X...... 1.... 2
61502 ... Y...... 3.....4

The list is quite long and every value that is returned is correct except for one: the first value. In this case it returns the a value which is one extra row down. If I change the look-up range to include the title row, ie "A61500:A65500" then it returns the correct value. Just wondering. Incidentally, I use the exact same code on three other lists and it only mistakes this mistake on one of them.
David
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
David

You aren't telling Find where to start looking.

So, and I'm not 100% sure about this, it's probably starting at the first cell after the first cell in the range it's looking in.

In this case that would be A61502.

Perhaps this will explain that better:
MSDN said:
If you do no specify this argument, the search starts after the cell in the upper-left corner of the range.
 
Upvote 0
AFTER the cell in the upper-left corner of the range...that would explain it. How do I specify the starting cell?
 
Upvote 0
With the After argument, or you could just start the range a row up.

That shouldn't cause any problems because the search should start in the right place.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

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