I have a table with Tickers and ID's.
ABC A1
XYZ A2
123 A3
Now I have my portfolio with the column names, ticker, CUSIP, ID.
In the ID tab I want to have the function do a vlookup on the ticker in the table with the tickers and ID's and give the result.
I also want it where if the ticker is not found in the table, it defaults back to A1.
This is what I have, but I doubt I'm even close to correct.
Function PortID(Ticker)
With Sheets("Portfolios")
PortID = Application.WorksheetFunction.VLookup(Ticker, Range("'Portfolios'!$B$14:$C$23"), 2, False)
If PortID = "#N/A" Then
PortID = Cells.C14
End If
End With
End Function
I have attached a file so you can see what I'm attempting to do.
Looking at the first one if upon the VLOOKUP, NWRXX is not found in the table, then result = A1. If it is found, give the corresponding Port-ID.
Thanks for the help.
Hi aeddipa,
you are almost get the results.
To check if ticker is not found, you can apply the iserror found
Results = Application.WorksheetFunction.VLookup(Ticker, Sheets("portfolios").Range("$B$14:$C$23"), 2, False)
If IsError(Results) Then
PortID = Cells.C14
End If
aeddipa & kimbal
You are both in breach of Forum Rule 3
Now both please wrap your VBA code
Please Read Forum Rules Before Posting
Wrap VBA code by selecting the code and clicking the # icon or Read This
How To Cross Post politely
Top Excel links for beginners to Experts
If you are pleased with a member's answer then use the Scales icon to rate it
If my reply has assistedor failed to assist you
I welcome your Feedback.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks