wsnyder
Board Regular
- Joined
- Sep 23, 2018
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
Hi all,
Using Excel 365.
I'm trying to build a VLookup Formula as a string in VBE so I can apply the formula to a Range using the Formula property of the Range Object.
I created a Function that returns a string
When in Break Mode, I hover on all of the variables, all fo the variables return expected values.
When I run the code, it returns an error:
I've looked at this for a couple of hours now and can't figure out what is wrong.
Any thoughts?
Thanks
-w
Using Excel 365.
I'm trying to build a VLookup Formula as a string in VBE so I can apply the formula to a Range using the Formula property of the Range Object.
I created a Function that returns a string
When in Break Mode, I hover on all of the variables, all fo the variables return expected values.
When I run the code, it returns an error:
and highlights my line where I am creating the formula stringRun-time error '438':
Object doesn't support this property or method
I've looked at this for a couple of hours now and can't figure out what is wrong.
Any thoughts?
Thanks
-w
VBA Code:
Private Function GetLookupFrmla(WhereFrmlaGoes As Range, _
LookupWhat As String, _
wb As Workbook, _
LookupArray As String, _
ReturnColNbr As Long) As String
'Purpose : Get lookup frmla
'Objects
Dim ws As Worksheet
'Initialize objects
Set ws = wb.Worksheets("Pivot")
'Get lookup frmla
GetLookupFrmla = "=IFERROR(VLOOKUP(" _
& LookupWhat & "," _
& "'[" & wb.name & "]" _
& ws.Name & "'!" _
& LookupArray & "," _
& ReturnColNbr & "," _
& "FALSE),0)"
'Tidy up
Set ws = Nothing
End Function