Problem with converting Xlookup function to WorksheetFunction.XLookup

WednesdayC

Board Regular
Joined
Nov 7, 2010
Messages
201
Office Version
  1. 2016
Platform
  1. MacOS
Hi Team

Sorry to post twice in one day - I am having a hard time with a workbook!

The following formula works fine in my VBA code for output to the cell:-

wsOutput.Cells(r, 3).FormulaR1C1 = _
"=XLOOKUP(" & strID & ", " & strCell & "!RC10:R1000C10," & strCell & "!RC12:R1000C12)"

Where StrCell is the name of a different worksheet - say "TEMP_1" for now.

I cannot workout how to convert this function so that the output is to a VBA variable instead, which I need.

Please can some help me.

Thank you in advance

Wednesday
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I'm on a Windows version of Excel, not a Mac version. So see if this works for you . . .

VBA Code:
    Dim myVar As Variant
    myVar = Application.XLookup(strID, Worksheets(strCell).Range("J2:J1000"), Worksheets(strCell).Range("L2:L1000"))
  
    If Not IsError(myVar) Then
        MsgBox "XLOOKUP returned " & myVar
    Else
        MsgBox "Match not found!", vbExclamation
    End If

Hope this helps!
 
Last edited:
Upvote 0
Solution
I'm on a Windows version of Excel, not a Mac version. So see if this works for you . . .

VBA Code:
    Dim myVar As Variant
    myVar = Application.XLookup(strID, Worksheets(strCell).Range("J2:J1000"), Worksheets(strCell).Range("L2:L1000"))
 
    If Not IsError(myVar) Then
        MsgBox "XLOOKUP returned " & myVar
    Else
        MsgBox "Match not found!", vbExclamation
    End If

Hope this helps!
Hi Domenic

Fantastic. It works! Thank you so much. I tried so many combinations, but obviously not the right one!

Best regards

Wednesday
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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