+ Reply to Thread
Results 1 to 3 of 3

Thread: VBA Help

  1. #1
    Registered User
    Join Date
    06-26-2009
    Location
    East Lansing, MI
    MS-Off Ver
    Excel 2003
    Posts
    4

    VBA Help

    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.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    06-15-2009
    Location
    Hong Kong, CN
    MS-Off Ver
    Excel 97-2010
    Posts
    17

    Re: VBA 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
    We build a new way to dream
    http://kimbalko.blogspot.com

  3. #3
    Forum Guru mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,984

    Re: VBA Help

    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 assisted or failed to assist you I welcome your Feedback.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0