Unable To Get VLookup Property Error Despite Numerous (Attempted) Workarounds

matt767

New Member
Joined
Apr 11, 2022
Messages
40
Office Version
  1. 365
Platform
  1. Windows
code excerpt:

VBA Code:
    Dim lc As Long
    lc = Cells(1, columns.Count).End(xlToLeft).column
    Dim cel2 As Range
    Dim srchrng As Range
    Set srchrng = Range(Cells(1, 39), Cells(1, lc))
    For Each cel2 In srchrng
    cel2.Offset(1, 0) = Application.WorksheetFunction.VLookup(ActiveSheet.Name & cel2, Sheets("mappings").Range("$G:$H"), 2, False)
    Next

Every time vlookup can't find a match, it returns the "Run-time error '1004': Unable to get the VLookup property of the WorksheetFunction class" error and stops the code. I have tried error handling using On Error Resume Next and On Error GoTo but when I do the vlookup doesn't return any values (but no error). I have also tried using an If Iserror(vlookup(...)) = True Then cel2.offset(1,0).value = "" Else cel2... = vlookup(...) and that also returns the same error when there is no match.

A separate issue is when the formatting of the cel2 range differs from the (non-formatted) range Sheets("mappings").Range("$G:$H") - vlookup again will not find a match. I have tried using cel2.text and cel2.value to no avail. I would like to be able to keep the formatting of my sheet.

Any help is appreciated. Thanks.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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