Young_Money
New Member
- Joined
- Jul 8, 2011
- Messages
- 23
Hi guys. I have a code that looks up the client initials and returns the cell to the right of it. However, I want this UDF to ONLY look in one sheet, "Reference_Location" for this information. However, I want the UDF to be able to be run in all worksheets in the excel file, ptwo.xlsm. How do I do this?
I know the Application.Workbooks part is incorrect, but I do not know how to correct it so that I can make it only use that ONE sheet.
Here is my code.
Function Custom_Lookup(ByVal Client_Initials As String) As String
Dim r
Application.Workbooks(“ptwo.xlsm").Worksheets(“Reference_Location”)
For Each r In Range("A:A")
If r = Client_Initials Then
Custom_Lookup = r.Offset(0, 1)
Exit Function
End If
Next
Custom_Lookup = "Not Found"
End Function
I know the Application.Workbooks part is incorrect, but I do not know how to correct it so that I can make it only use that ONE sheet.
Here is my code.
Function Custom_Lookup(ByVal Client_Initials As String) As String
Dim r
Application.Workbooks(“ptwo.xlsm").Worksheets(“Reference_Location”)
For Each r In Range("A:A")
If r = Client_Initials Then
Custom_Lookup = r.Offset(0, 1)
Exit Function
End If
Next
Custom_Lookup = "Not Found"
End Function