Forum

VBA Error with Xloo...
 
Notifications
Clear all

[Solved] VBA Error with Xlookup

3 Posts
2 Users
1 Reactions
438 Views
(@alancannon44)
Posts: 3
Active Member
Topic starter
 

I have a problem with using Xlookup in a macro. VBA gives this error:

Run-time error '424':
Object required

Here is the relevant VBA code:

FullName = ActiveSheet.Range("$C$14").Value
FindName = WorksheetFunction.XLookup(FullName, tblPhones![Full], tblPhones![Phone], "New Name")

I am at a loss trying to figure this out. The XLookup as a formula directly in the worksheet as a test and replacing FullName with the cell address works just fine with the ! removed in the table references, but in the macro I get a different error if I don't include the !. I am running Excel 365.

 
Posted : 10/01/2025 3:15 am
(@debaser)
Posts: 837
Member Moderator
 

You can't refer to table ranges like that. You need to use something like:

FindName = WorksheetFunction.XLookup(FullName, Application.Range("tblPhones[Full]"), Application.Range("tblPhones[Phone]"), "New Name")
This post was modified 4 months ago by Catalin Bombea
 
Posted : 11/01/2025 2:59 am
AlanCannon44 reacted
(@alancannon44)
Posts: 3
Active Member
Topic starter
 

Thanks Velouria! That fixed it.

 
Posted : 11/01/2025 5:29 am
Share: