+ Reply to Thread
Results 1 to 18 of 18

UDF to extract specified text

  1. #1
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    UDF to extract specified text

    Hi

    I want to replace a laborious find, copy paste task, is a udf for text extraction possible where the text to be extracted is specified each time it's run?

    thanks

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: UDF to extract specified text

    A. UDF - is a custom function...it does not get "Run" like a normal macro
    B. You are going to have to be a lot more specific
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    Re: UDF to extract specified text

    I'm trying to form links between 2 datasets and there's a free text field in each that has a common reference, although there are a lot of the common references, So I want a function I can apply to a helper column where I get to change the alphanumeric to be extracted

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: UDF to extract specified text

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window (or use the paperclip icon).

  5. #5
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    Re: UDF to extract specified text

    There's a 2 sheet sample here, with columns in of the extracted data, there are maybe 30 different alphanumerics to be extracted into helper columns from maybe 120000 rows
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: UDF to extract specified text

    Please Login or Register  to view this content.
    here is what i ended up with
    Ext(LookAt As Range, lookFor As Range, Count As Integer)

    3 conditions of function
    lookat = what you want to look
    lookFor = list of terms you want to look for....in this example i have a list of terms in the worksheet...suggest using a named range for this so its easily maintained
    count = this is the equivalent of your UDF1, UDF2,UDF3, ie 1st match, 2nd match, etc
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    Re: UDF to extract specified text

    Hi humdingaling

    This looks fantastic, myvba is very limited and even when reverse engineering something i struggle, using a named range will be better, as the example doesn't cover all search terms, plus i can do variations such as 2 Mbps and 2Mbps etc, which bit of the code do i replace with a named range?

    thanks again, this is just the ticket

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: UDF to extract specified text

    i've uploaded the file with what i mean by named range

    added new sheet (not necessary for new sheet but seems cleaner to do so)
    created named range called list
    made it refer to A2:A16
    update this named range and it will update all the formulas automatically where it is used

    re:
    nuances with having a space and not having a space (with Mbps for example)

    i suppose mode coding can be done to draw out the answer
    ie check if " " before Mbps if not then do this, etc

    the section of the code that does that is the select case
    Please Login or Register  to view this content.
    essentially only look for Mbps (or Gbps, Sip Trunks...add more here if you have more terms like these)

    ill have another look at it tomorrow
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    Re: UDF to extract specified text

    Thank you so much, this is really helpful and gives me some great wins, I'll look at the amendments and try and get my head around the code, I'll try and update the range and upload that too

  10. #10
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    Re: UDF to extract specified text

    Hi humdingaling

    Thanks again for all of this i really appreciate the effort and the input, I'm going through the code, and I get the named range and how to manage/update that, what I can't see is where in the code it refers itself to "list", and also, bear with me here-VBA is a weakness of mine, if we're now referring to a range list why is there still the case part of the script with the three main instances (Mbps, Gbps, SIP Trunks) when these and the variants could just be in the list? Sorry if i'm asking the obvious here........

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,207

    Re: UDF to extract specified text

    The CASE is used to determine the numeric values associated with the specific list values of "Mbps, Gbps , SIP Trunks".



    the "lookFor" range in the code refers to the named range List

    in Macro ....

    Function Ext(LookAt As Range, lookFor As Range, Count As Integer)

    In your cells ...

    =ext($A2,list,G$1)

    $A2 = LookAt

    list = lookFor

    G$1 = Count

    Hope this helps.

  12. #12
    Forum Contributor Gregor y's Avatar
    Join Date
    10-24-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2010 32-Bit
    Posts
    276

    Re: UDF to extract specified text

    why not just add 30 colums, one for each search term Stored in Row1, then use the cell formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Gregor y; 04-19-2016 at 04:49 PM. Reason: add $
    If it'd make you feel better using my answer because of my street cred, then you can go ahead and click Add Reputation below to improve it.

  13. #13
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: UDF to extract specified text

    i've gone thru and added comments on most of the code
    also made a change on how terms that require Numeric prefix's are handled

    hopefully this helps

    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    Re: UDF to extract specified text

    OK, ignore my previous about the count part, I've been doing more testing and think I've got that now, this works fine and gives me a run of extraction columns to work from, i think from here I can just adjust the list and run through additional columns until that count doesn't bring back results and then from there i can build my fourth condition

    thanks again so much for your input, time and effort, it's more appreciated than you know
    Last edited by jyadayada; 04-25-2016 at 02:08 PM. Reason: user error!

  15. #15
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: UDF to extract specified text

    the count part works just like Small or Large formula does

    not a problem

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  16. #16
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    Re: UDF to extract specified text

    My understanding of small and large is as it sounds, the smallest or largest value, I've run counts 1-5 across 5 columns and had differing results across the columns, my assumption being that count 1 takes the first instance of a match from the list, 2 the 2nd and so on?

  17. #17
    Forum Contributor
    Join Date
    02-16-2010
    Location
    Manchester, England
    MS-Off Ver
    Microsoft 365 for Enterprise
    Posts
    103

    Re: UDF to extract specified text

    this already posted but in my refresh it looked like it hadn't...
    Last edited by jyadayada; 04-26-2016 at 10:34 AM. Reason: duplication

  18. #18
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: UDF to extract specified text

    yes

    http://www.techonthenet.com/excel/formulas/small.php
    Small gives you the smallest number in nth position of selected range

    ie
    small(range,1) will give you the smallest
    small(range,2) will give you the second smallest
    etc

+ 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. VBA to open saved web html pages - extract text - paste text within individual cell
    By EddieRubi in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-23-2015, 01:43 PM
  2. Replies: 2
    Last Post: 05-13-2015, 06:52 AM
  3. Extract text between two characters in a string - varing text length
    By luv2birdie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-04-2014, 06:10 PM
  4. Replies: 4
    Last Post: 08-13-2014, 11:03 PM
  5. [SOLVED] Extract text from a given point in a text string, when data points do not share the given
    By reedersketer in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-09-2014, 03:57 PM
  6. [SOLVED] Extract text from a string of text (amend formula to include new criteria)
    By robertguy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-10-2013, 04:53 PM
  7. Compare two text cells and extract common text words
    By ghost_chip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2012, 06:07 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