+ Reply to Thread
Results 1 to 4 of 4

UDF that extracts specific text from cell based on user input string

  1. #1
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    UDF that extracts specific text from cell based on user input string

    Hi,

    Looking to create a UDF that extracts a specific portion of a cell based on a input from the user.

    Example data:

    ModelResults
    [{"name":"PMML.Model1","outputs":{"Predicted_decision":"APPROVE","Probability_APPROVE":"0.5","Probability_REJECT":"0.5"}},{"name":"PMML.Model2","outputs":{"Predicted_decision":"APPROVE","Probability_APPROVE":"1.0","Probability_REJECT":"0.0"}},{"name":"PMML.Model3","outputs":{"Predicted_decision":"APPROVE","Probability_APPROVE":"0.94","Probability_REJECT":"0.06"}},{"name":"PMML.Model4","outputs":{"Predicted_decision":"REJECT","Probability_APPROVE":"0.16613686480221865","Probability_REJECT":"0.8338631351977813"}}]

    The column is a named range called "ModelResults" and it contains a series of outputs from several models, using made up names "PMML.Model1", "PMML.Model2" etc., the files may be 1000s of rows long.
    Each model output is contained inside { } brackets, separated by commas.
    There may be different models per row or some that aren't always present but the { } delimiter and the "PMML.####" name is consistent.

    I currently use a nested FIND formula to extract the part that I'm after between the { } brackets.
    Example using "Model3":

    Please Login or Register  to view this content.

    Model3 extracted with formula
    {"name":"PMML.Model3","outputs":{"Predicted_decision":"APPROVE","Probability_APPROVE":"0.94","Probability_REJECT":"0.06"}}

    My desired function: To be able to type e.g. =ModelOutput(Model3) in a cell and return the corresponding output directly instead of using the formula. It could return blank or "N/A" if the model output doesn't exist. Is this possible?

    I've attached a dummy spreadsheet.
    Attached Files Attached Files
    Last edited by Tunesmith; 07-04-2018 at 10:42 AM. Reason: solved

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: UDF that extracts specific text from cell based on user input string

    If it's a UDF you want you'll need 2 inputs, one the model you are looking for and one the cell to check.

    Something like this.
    Please Login or Register  to view this content.
    Which could be used like this.

    =ModelOutput("Model3",B2)
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: UDF that extracts specific text from cell based on user input string


    Hi !

    So you want an UDF which performs the same than your formula and maybe in a slower way, right ?

    In this case the formula in C2 cell will be =ModelOutput(B2,"Model3")

    Edit : too late …

  4. #4
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    Re: UDF that extracts specific text from cell based on user input string

    Quote Originally Posted by Norie View Post
    If it's a UDF you want you'll need 2 inputs, one the model you are looking for and one the cell to check.

    Something like this.
    Please Login or Register  to view this content.
    Which could be used like this.

    =ModelOutput("Model3",B2)
    Quote Originally Posted by Marc L View Post

    Hi !

    So you want an UDF which performs the same than your formula and maybe in a slower way, right ?

    Edit : too late …
    A slower calculation speed isn't necessarily an issue for the use case so this solution works great, thank you both!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] A vba code that extracts a specific text along with the next 8 digit number that follows
    By ermias in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-04-2018, 08:45 AM
  2. [SOLVED] Delete specific range cell data based on user input
    By terriertrip in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-06-2017, 07:57 PM
  3. Replies: 24
    Last Post: 11-10-2015, 07:27 PM
  4. user defined macro to replace certain characters in a string based on user input
    By whatappears in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2012, 06:25 PM
  5. Using text box input to lookup number and replace based on user input into new column
    By harl3y412 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2011, 03:15 PM
  6. Conditional formating based on specific text in string in another cell
    By mraheelgujjar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-12-2011, 01:09 PM
  7. Auto Generation of String based on user input
    By dhimbak in forum Excel General
    Replies: 3
    Last Post: 06-04-2009, 09:12 AM

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.6.0 RC 1