+ Reply to Thread
Results 1 to 5 of 5

Extracting data from a sentence.

Hybrid View

  1. #1
    Registered User
    Join Date
    07-02-2014
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    33

    Extracting data from a sentence.

    What's up all-stars,

    My client is a repair service who has a poorly constructed database when it comes to data trending (lots of free text fields). While I'm working with them on normalizing their data, they want to be able to do trending on their years of previous sentence-format information. Does anyone know how to do part-of-speech tagging and grammatical parsing in excel or can anyone otherwise point me in the right direction?

    For example, these sentences
    The capacitor failed due to dielectric breakdown.
    Faulty capacitor (dielectric breakdown).
    The cap is bad. Appears to have suffered dielectric breakdown.
    would all yield the same data:
    PART          FAILURE_MODE
    capacitor     dielectric breakdown
    capacitor     dielectric breakdown
    capacitor     dielectric breakdown

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,651

    Re: Extracting data from a sentence.

    Can you give more other PARTS and more FAILURE MODE that may occurred during previous years?
    Quang PT

  3. #3
    Registered User
    Join Date
    07-02-2014
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    33

    Re: Extracting data from a sentence.

    Sure can. See the attached excel file.

    I tried out the SMILE Text Analyzer and got the following part-of-speech tagged output for my example sentences:

    The/DT capacitor/NN failed/VBD due/JJ to/TO dielectric/JJ breakdown/NN ./.  
    Faulty/NN capacitor/NN (/( dielectric/JJ breakdown/NN )/) ./.  
    The/DT cap/NN is/VBZ bad/JJ ./.  
    Appears/NNS to/TO have/VB suffered/VBN dielectric/JJ breakdown/NN ./.
    Here is the key of what each part-of-speech means:
    •CC - Coordinating conjunction
    •CD - Cardinal number
    •DT - Determiner
    •EX - Existential there
    •FW - Foreign word
    •IN - Preposition or subordinating conjunction
    •JJ - Adjective
    •JJR - Comparative adjective
    •JJS - Superlative adjective
    •LS - List Item Marker
    •MD - Modal verb
    •NN - Singular noun
    •NNS - Plural noun
    •NNP - Proper singular noun
    •NNPS - Proper plural noun
     •PDT - Predeterminer
    •POS - Possesive ending
    •PRP - Personal pronoun
    •PRP$ - Possesive pronoun
    •RB - Adverb
    •RBR - Comparative adverb
    •RBS - Superlative Adverb
    •RP - Particle
    •SYM - Symbol
    •TO - to
    •UH - Interjection
    •VB - Verb, base form
    •VBD - Verb, past tense
    •VBG - Verb, gerund/present participle
    •VBN - Verb, past participle
     •VBP - Verb, non 3rd ps. sing. present
    •VBZ - Verb, 3rd ps. sing. present
    •WDT - wh-determiner
    •WP - wh-pronoun
    •WP$ - Possesive wh-pronoun
    •WRB - wh-adverb
    •$ - Dollar sign
    •. - Sentence-break punctuation . ? !
    •# - Pound sign
    •- - Dash sign
    •, - Comma
    •: - Colon, semi-colon
    •( - Open parenthesis ) ] }
    •) - Close parenthesis ) ] }
    •`` - Open quote
    •'' - Close quote
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Extracting data from a sentence.

    Hi IcyBricks,

    Does anyone know how to do part-of-speech tagging and grammatical parsing in excel or can anyone otherwise point me in the right direction?
    I'm not a word person, so I took a slightly different approach. I looked at KEYWORDS in an attempt to match 'Part Names', and 'Failure Modes' for the 'Part Names'.

    Algorithm used:
    a. Copy the 'RawData' Sheet Contents to the 'Scratch' Sheet ('Data Area').
    Column 'A' contains a sentence to be processed on each line (.e.g. 'The 150pf capacitor was leaking.').
    b. Create a Dictionary (list) of unique 'Part Names' from the sheet containing the MASTER 'Part Name' list.
    c. Remove extraneous words (.e.g. 'the') and remove punctuation from the 'Data Area'.
    There is a list of extraneous words and extraneous symbols on the sheet containing the MASTER 'Useless Items' list.
    d. Replace abbreviations (and other items) in the 'Data Area' with synonyms (e.g. replace 'cap' with 'capacitor').
    Some words are manipulated to be able to match 'Part Name' or 'Failure Mode' keywords (e.g. 'power cord' becomes 'Power Cord/Converter').
    There is a list of synonyms on the sheet containing the MASTER 'Synonym' list.
    e. Process One Raw Data sentence (one per line) at a time.
    (1) Find a matching 'Part Name'.
    (2) Get potential 'Failure Mode' Text for that Part Name.
    (3) STOP with a MATCH, If the 'Failure Mode' Text is contained VERBATIM in the 'Raw Data' Sentence.
    (4) STOP with a MATCH, If all the 'Failure Mode' Text WORDS are contained in the 'Raw Data' Sentence.
    (5) Count the number of 'Failure Mode' Text WORDS contained in the 'Raw Data' Sentence.
    (6) Repeat steps (2) thru (5) until a MATCH has been found, or there is no more 'Failure Mode' Text for the Part Name.
    (7) Declare a MATCH for the 'Failure Mode' Text that contains the MOST words in the 'Raw Data' Sentence.

    Lewis

    See the attached file and code that follows and is continued in the next post:
    Option Explicit
    
    Public Const ASCII_SPACE = " "
    
    Public Const sRawDataSheetNAME = "RawData"
    Public Const sRawDataSheetInputCOLUMN = "A"
    Public Const sRawDataSheetOutputPartNameCOLUMN = "I"
    Public Const sRawDataSheetOutputFailureModeCOLUMN = "L"
    
    Public Const sKeyWordsSheetNAME = "KeyWords"
    Public Const sKeyWordsSheetPartNameCOLUMN = "A"
    Public Const sKeyWordsSheetFailureModeCOLUMN = "B"
    
    Sub ClearResultsColumsOnSheetRawData()
      ThisWorkbook.Sheets(sRawDataSheetNAME).Columns(sRawDataSheetOutputPartNameCOLUMN).ClearContents
      ThisWorkbook.Sheets(sRawDataSheetNAME).Columns(sRawDataSheetOutputFailureModeCOLUMN).ClearContents
    End Sub
    
    
    Sub FaultIsolation()
    
      Dim myKeyWordDictionary As Object
    
      Dim wsExtraneousWordList As Worksheet
      Dim wsKeyWords  As Worksheet
      Dim wsRawData As Worksheet
      Dim wsScratch As Worksheet
      Dim wsSynonymList As Worksheet
      
      Dim i As Long
      Dim iLastRowUsedInColumn As Long
      Dim iLastIndex As Long
      Dim iRow As Long
      
      Dim bHavePartName As String
      
      Dim xColumnWidth As Double
      
      Dim a() As String
      Dim sFailureMode As String
      Dim sSentenceFragment As String
      Dim sValue As String
      Dim sValueToShowUsers As String
      
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Initialization
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      
      Application.DisplayStatusBar = True
      Application.StatusBar = "Prelmininary Fault Isolation Processing in Progress"
    
      Set wsExtraneousWordList = Sheets("Sheet1")
      Set wsSynonymList = Sheets("Sheet1")
      Set wsKeyWords = Sheets("Sheet1")
      Set wsRawData = Sheets(sRawDataSheetNAME)
      Set wsScratch = Sheets("Scratch00")
      
      'Create the dictionary object
      'Set comparison mode to CASE INSENSITIVE (vbTextCompare)
      Set myKeyWordDictionary = CreateObject("Scripting.Dictionary")
      myKeyWordDictionary.CompareMode = vbTextCompare
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Clear the Scratch Sheet
      'Copy the Contents of the Raw Data Sheet to the Scratch Sheet (and clear the ClipBoard buffer)
      'Remove all Shapes on the 'Scratch' Sheet
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      wsScratch.Cells.Clear
      wsRawData.Cells.Copy Destination:=wsScratch.Range("A1")
      Application.CutCopyMode = False
      wsScratch.DrawingObjects.Delete
      
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Clear the Results Columns from the 'Raw Data' Sheet
      'Make the results Columns the same width as the KeyWords Sheet 'Part Name' and 'Failure Mode' Columns
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      wsRawData.Columns(sRawDataSheetOutputPartNameCOLUMN).ClearContents
      wsRawData.Columns(sRawDataSheetOutputFailureModeCOLUMN).ClearContents
      
      xColumnWidth = wsKeyWords.Columns(sKeyWordsSheetPartNameCOLUMN).ColumnWidth
      wsRawData.Columns(sRawDataSheetOutputPartNameCOLUMN).ColumnWidth = xColumnWidth
        
      xColumnWidth = wsKeyWords.Columns(sKeyWordsSheetFailureModeCOLUMN).ColumnWidth
      wsRawData.Columns(sRawDataSheetOutputFailureModeCOLUMN).ColumnWidth = xColumnWidth
      
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Create a list of Unique Part Name
      'Any embedded space in a Part Name is replaced with a tilde '~'
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Call CreateKeyWordDictionary(wsKeyWords, myKeyWordDictionary)
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Preprocess the data in the Scratch area by attempting to create 'Part Names' from
      'individual words in the data sentences (e.g. 'Check Valve' becomes 'Check~Valve'
      'This is to make 'Part Names' in the 'Scratch' area match the names in the 'Dictionary'
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Call BuildPartNamesFromIndividualWords(wsScratch, myKeyWordDictionary)
      
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Remove Extraneous Words and Extraneous Characters
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Call RemoveExtraneousItems(wsExtraneousWordList, wsScratch)
    
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Replace abbreviations with synonmyms
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Call ReplaceTokenWithSynonym(wsSynonymList, wsScratch)
    
    
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Find the matching Failure modes
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      
      'Get the last row used in Column 'A' in the 'KeyWords Worksheet'
      iLastRowUsedInColumn = wsScratch.Columns("A:A").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
      
      For iRow = 1 To iLastRowUsedInColumn
      
         Application.StatusBar = "Finding Failure Mode for Item " & iRow & " of " & iLastRowUsedInColumn & " total items."
        
        'Read the next sentence fragment
        'Parse the fragment into spaced delimited tokens
        sSentenceFragment = wsScratch.Cells(iRow, "A").Value
        iLastIndex = LjmParseString(sSentenceFragment, a)
        
        bHavePartName = False
        
        If iLastIndex >= 0 Then
          For i = 0 To iLastIndex
          
            'See if the next token is a PART Name
            'If a PART Name, save the token as the FAILED part
            'Remove the PART Name from the Sentence Fragment
            sValue = Trim(a(i))
            If myKeyWordDictionary.exists(sValue) = True Then
            
              'Set the flag that indicates that a MATCHING 'Part Name' was found
              bHavePartName = True
            
              'Write down the 'Part Name' as part of the solution
              sValueToShowUsers = myKeyWordDictionary.Item(sValue)
              'wsScratch.Cells(iRow, "G") = sValueToShowUsers
              wsRawData.Cells(iRow, sRawDataSheetOutputPartNameCOLUMN) = sValueToShowUsers
              
              'Remove the 'Part Name' from the 'Sentence Fragment' on the Scratch Sheet
              sValue = ASCII_SPACE & sValue & ASCII_SPACE
              sSentenceFragment = ASCII_SPACE & sSentenceFragment & ASCII_SPACE
              sSentenceFragment = Replace(sSentenceFragment, sValue, "")
              wsScratch.Cells(iRow, "A").Value = sSentenceFragment
              
              'Find the 'Failure Mode'
              sValue = Trim(sValue)
              sFailureMode = GetMatchingFailureMode(wsKeyWords, sValue, sSentenceFragment)
              
              'Write down the 'Failure Mode' as part of the solution
              'wsScratch.Cells(iRow, "I").Value = sFailureMode
              wsRawData.Cells(iRow, sRawDataSheetOutputFailureModeCOLUMN).Value = sFailureMode
              
            End If
          Next i
          
          If bHavePartName = False Then
           sValueToShowUsers = "No Matching Part Name"
           'wsScratch.Cells(iRow, "G") = sValueToShowUsers
           wsRawData.Cells(iRow, sRawDataSheetOutputPartNameCOLUMN) = sValueToShowUsers
          End If
        End If
      Next iRow
      
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      'Termination
      '''''''''''''''''''''''''''''''''''''''''''''''''''''''
      
      'Return Status Bar Control to Excel
      Application.StatusBar = False
    
      
      'Clear object pointers
      Set wsExtraneousWordList = Nothing
      Set wsKeyWords = Nothing
      Set wsScratch = Nothing
      Set wsSynonymList = Nothing
    
    End Sub
    Attached Files Attached Files
    Last edited by LJMetzger; 02-21-2015 at 02:58 PM.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Extracting data from a sentence.

    Code for previous post part 2:
    Sub CreateKeyWordDictionary(wsKeyWords As Worksheet, myKeyWordDictionary As Object)
      'This creates a Dictionary of Unique KeyWords
      'KEY  = Unique Name (with tilde replacing spaces)
      'ITEM = Unique Name before tilde replaced spaces
    
      Dim iLastRowUsedInColumn As Long
      Dim iRow As Long
      Dim sValue As String
      Dim sValueOriginal As String
      
      'Get the last row used in Column 'A' in the 'Keywords Worksheet'
      iLastRowUsedInColumn = wsKeyWords.Columns("A:A").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
      
      'Process each row in the Worksheet
      'Read each value removing leading/trailing spaces
      'Replace embedded spaces with Tilde '~'
      'Replace Forward Slash with Tilde '~'
      For iRow = 2 To iLastRowUsedInColumn
        sValue = wsKeyWords.Cells(iRow, "A").Value
        sValue = Trim(sValue)
        sValueOriginal = sValue
        sValue = Replace(sValue, " ", "~")
        If myKeyWordDictionary.exists(sValue) = False Then
          myKeyWordDictionary.Add sValue, sValueOriginal
        End If
      Next iRow
    
    End Sub
    
    Sub BuildPartNamesFromIndividualWords(wsScratch As Worksheet, myKeyWordDictionary As Object)
      'This builds potential Part Names in the data area by replacing certain SPACES with tildes
      'This is to make 'Part Names' in the 'Scratch' area match the names in the 'Dictionary'
      
      Dim myRange As Range
    
      Dim i As Long
      
      Dim sPartName As String
      Dim sPartNameLessTildes As String
      
      'Create the replacement range
      Set myRange = wsScratch.Columns("A:A")
      
      For i = 0 To myKeyWordDictionary.Count - 1
        sPartName = myKeyWordDictionary.keys()(i)
        'Debug.Print i, sPartName
        If InStr(sPartName, "~") > 0 Then
          sPartNameLessTildes = Replace(sPartName, "~", " ")
          Call LjmUniversalReplace(myRange, sPartNameLessTildes, sPartName)
        
          'Debug.Print i, sPartName, sPartNameLessTildes
        End If
      Next i
      
      'Clear object pointers
      Set myRange = Nothing
      
    End Sub
    
    Sub RemoveExtraneousItems(wsExtraneousWordList As Worksheet, wsScratch As Worksheet)
      'This removes extraneous words and punctuation from the 'Raw Data' Sheet
    
      Dim myRange As Range
    
      Dim iLastRowUsedInColumnInExtraneousWordColumn As Long
      Dim iLastRowUsedInScratchSheet As Long
      Dim iRow As Long
      Dim sNew As String
      Dim sOriginal As String
      Dim sValue As String
      
      'Create the replacement range
      Set myRange = wsScratch.Columns("A:A")
      
      iLastRowUsedInScratchSheet = wsScratch.Columns("A:A").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
      
      'Get the last row used in Column 'G' in the 'Extraneous Word Worksheet'
      iLastRowUsedInColumnInExtraneousWordColumn = wsExtraneousWordList.Columns("G:G").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
      
      'Put a leading and trailing space in each data line on the Scratch Sheet
      For iRow = 1 To iLastRowUsedInScratchSheet
        sValue = Trim(wsScratch.Cells(iRow, "A").Value)
        sValue = ASCII_SPACE & sValue & ASCII_SPACE
        wsScratch.Cells(iRow, "A").Value = sValue
      Next iRow
      
      'Read each line from the 'Extraneous Word List'
      'Replace each 'Extraneous Word' on the 'Scratch' Sheet with an ASCII SPACE
      sNew = ASCII_SPACE
      For iRow = 1 To iLastRowUsedInColumnInExtraneousWordColumn
      
        sOriginal = Trim(wsExtraneousWordList.Cells(iRow, "G").Value)
        If Left(sOriginal, 1) = "~" Then
          sValue = Right(sOriginal, Len(sOriginal) - 1)
        Else
          sValue = ASCII_SPACE & sOriginal & ASCII_SPACE
        End If
        
        Call LjmUniversalReplace(myRange, sValue, sNew)
      
      Next iRow
      
      'Clear object pointers
      Set myRange = Nothing
      
    End Sub
    
    
    Sub ReplaceTokenWithSynonym(wsSynonymList As Worksheet, wsScratch As Worksheet)
      'This replaces words and phrases with Synonyms (e.g. to replace 'Cap' with 'Capacitor'.
      '
      'Occassionally this is used to create phrases that are consistent throughout
    
      Dim myRange As Range
      
      Dim iLastRowUsedInColumn As Long
      Dim iRow As Long
      Dim sNew As String
      Dim sOriginal As String
      Dim sValue As String
      
      'Get the last row used in Column 'G' in the 'Extraneous Word Worksheet'
      iLastRowUsedInColumn = wsSynonymList.Columns("I:I").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
      
      'Create the replacement range
      Set myRange = wsScratch.Columns("A:A")
      
      'Read each line from the 'Synonym Word List'
      'Replace each 'Synonym Word' in the Sheet with it's synonym
      For iRow = 2 To iLastRowUsedInColumn
      
        sOriginal = Trim(wsSynonymList.Cells(iRow, "I").Value)
        sValue = ASCII_SPACE & sOriginal & ASCII_SPACE
        sNew = Trim(wsSynonymList.Cells(iRow, "J").Value)
        sNew = ASCII_SPACE & sNew & ASCII_SPACE & ASCII_SPACE
        Call LjmUniversalReplace(myRange, sValue, sNew)
        'Debug.Print iRow, sValue, sNew
      
      Next iRow
    
      'Clear object pointers
      Set myRange = Nothing
      
    End Sub
    
    Function GetMatchingFailureMode(wsKeyWords As Worksheet, sInputPartName As String, sSentenceFragment As String) As String
      'This returns the 'Failure Mode' as a string if the 'Failure Mode' is Found
    
    
      Dim r As Range
      
      Dim a() As String
      
      Dim i As Long
      Dim iLastIndex As Long
      Dim iMatchingTokenCount As Long
      Dim iMaxMatchingTokenCount As Long
      
      Dim bFoundMatchingFailureMode As Boolean
      Dim bNeedMore As Boolean
      
      Dim sAddress As String
      Dim sFailureMode As String
      Dim sFirstAddress As String
      Dim sMatchingAddress As String
      Dim sPartName As String
      Dim sValue As String
      
      'Create a local copy of the 'Part Name'
      'Replace tildes in the 'Part Name' with spaces
      sPartName = Trim(sInputPartName)
      sPartName = Replace(sPartName, "~", " ")
      
      'Debug.Print "'''''''''''''''''''''''''''''''"
      'Debug.Print "Looking for failure mode for: " & sSentenceFragment
      
      'Find the first Matching 'Part Name'
      'Get the 'Address' of the first match
      'Get the 'Failure Mode' associated with the 'Part Name'
      Set r = LjmFindFirst(wsKeyWords, sPartName)
      sFirstAddress = r.Address(False, False)
      sFailureMode = Trim(r.Offset(0, 1).Value)
      'Debug.Print r.Address(False, False), sFailureMode
      
      bNeedMore = True
      While bNeedMore
      
        'Replace DASH and SLASH in the 'Failure Mode' string with spaces
        sFailureMode = Replace(sFailureMode, "-", ASCII_SPACE)
        sFailureMode = Replace(sFailureMode, "/", ASCII_SPACE)
      
        'Determine if the ENTIRE 'Failure Mode' is contained VERBATIM in the 'Sentence Fragment'
        If InStr(UCase(sSentenceFragment), UCase(sFailureMode)) > 0 Then
          bNeedMore = False
          bFoundMatchingFailureMode = True
          sMatchingAddress = r.Address(False, False)
          iMatchingTokenCount = iMatchingTokenCount + 1
          iMaxMatchingTokenCount = iMaxMatchingTokenCount + 1
          'Debug.Print "Matching Failure Mode = " & sFailureMode
        Else
          
          
          'Otherwise, Determine if the ENTIRE 'Failure Mode' is contained PIECE by PIECE in the 'Sentence Fragment'
          iLastIndex = LjmParseString(sFailureMode, a)
        
          'Process the 'Failure Mode' words one at a time
          If iLastIndex >= 0 Then
            For i = 0 To iLastIndex
          
              'See if the next token is a PART Name
              'If a PART Name, save the token as the FAILED part
              'Remove the PART Name from the Sentence Fragment
              sValue = UCase(Trim(a(i)))
              'Debug.Print sValue
              If InStr(UCase(sSentenceFragment), sValue) > 0 Then
                'Debug.Print "Matched token for:" & sValue
                
                'Increment the Matching Token Count
                iMatchingTokenCount = iMatchingTokenCount + 1
                
                'Increment the 'Max' Matching Token Count if the 'Max' value has been exceeded
                If iMatchingTokenCount > iMaxMatchingTokenCount Then
                  iMaxMatchingTokenCount = iMatchingTokenCount
                  sMatchingAddress = r.Address(False, False)
                End If
                
                'If all the tokens in the 'Failure Mode' have been Matched, STOP - becuase there is a 100% match
                If iMatchingTokenCount = iLastIndex + 1 Then
                  bNeedMore = False
                  bFoundMatchingFailureMode = True
                  sMatchingAddress = r.Address(False, False)
                  'Debug.Print "Matching Failure Mode = " & sFailureMode
                End If
              End If
            Next i
          End If
        End If
      
        'If there is NO MATCH, Get the Next 'Failure Mode' for this 'Part Name'
        'STOP with NO MATCH, if all the 'Failure Modes' for this 'Part Name' have been processed
        If bFoundMatchingFailureMode = False Then
          'Find the next Matching 'Part Name'
          'Get the 'Address' of the match
          Set r = wsKeyWords.Columns("A").FindNext(After:=r)
          sAddress = r.Address(False, False)
        
          'if NOT the first address (2nd time around), Get the 'Failure Mode' associated with the 'Part Name'
          'Otherwise, it is the end of data - exit
          If sAddress <> sFirstAddress Then
            sFailureMode = Trim(r.Offset(0, 1).Value)
            'Debug.Print r.Address(False, False), sFailureMode
          Else
            bNeedMore = False
          End If
        End If
        
      Wend
      
      'Return the Matching 'Failure Mode' to the calling routine
      'Return a message if 'Failure Mode' could not be found
      If iMaxMatchingTokenCount > 0 Then
        GetMatchingFailureMode = Trim(wsKeyWords.Range(sMatchingAddress).Offset(0, 1).Value)
      Else
        GetMatchingFailureMode = "Unable to Determine Failure Mode"
      End If
    
    End Function
    
    
    Sub LjmUniversalReplace(myRange As Range, sOriginal As String, sNew As String)
      'This performs a Universal replace (case insensitive) on a range
      '
      'NOTE: To match entire words and not words inside of words (e.g. 'the' and 'theme'), the 'Original'
      '      String SHOULD contain one leading and one trailing space.
      '      the 'New' String should also contain one leading and one trailing space.
      
      myRange.Replace _
        What:=sOriginal, _
        Replacement:=sNew, _
        LookAt:=xlPart, _
        MatchCase:=False
    End Sub
    
    Function LjmParseString(InputString As String, ByRef sArray() As String) As Long
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '
    ' This parses a space delimited string into an array of tokens.
    ' Leading and trailing spaces are stripped from the string in the process.
    '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
      Dim i As Integer
      Dim LastNonEmpty As Integer
      Dim iSplitIndex As Integer
    
     'Initialization
      LastNonEmpty = -1
      
      'Split the string into tokens
      sArray = Split(InputString)
      iSplitIndex = UBound(sArray)
    
     'Remove the null tokens
      For i = 0 To iSplitIndex
    
        If sArray(i) <> "" Then
           'Get rid of all the whitespace
            LastNonEmpty = LastNonEmpty + 1
            sArray(LastNonEmpty) = sArray(i)
        End If
      Next i
    
    
     'Return the number of indices
      LjmParseString = LastNonEmpty
      
    End Function
    
    Function LjmFindFirst(ws As Worksheet, sFindString As String) As Range
      'This returns the address (as a string) of the first occurrence of a 'find string'
      
      Dim r As Range
      
      'Find the first occurence of the string
      Set r = Nothing
      Set r = ws.Columns("A").Find(What:=sFindString, _
                          After:=ws.Range("A1"), _
                          LookIn:=xlValues, _
                          LookAt:=xlWhole, _
                          SearchOrder:=xlByRows, _
                          SearchDirection:=xlNext, _
                          MatchCase:=False, _
                          SearchFormat:=False)
                          
                          
      If Not r Is Nothing Then
      
        'Save the found address as the return value as a string
        Set LjmFindFirst = r
      End If
     
      'Clear the object pointer
      Set r = Nothing
     
    End Function

+ 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. Extracting data from file in directory and extracting filename
    By brad999 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2014, 11:21 AM
  2. Extracting value from sentence
    By MEMEs in forum Excel General
    Replies: 2
    Last Post: 07-06-2010, 10:10 AM
  3. Extracting a number out of a sentence
    By Geomarsh in forum Excel General
    Replies: 17
    Last Post: 08-12-2009, 09:47 PM
  4. Excel 2007 : pulling data from a sentence
    By shaun.murray in forum Excel General
    Replies: 1
    Last Post: 01-27-2009, 11:23 AM
  5. Extracting a Word from a cell that contains a sentence
    By onuwayhid in forum Excel General
    Replies: 1
    Last Post: 02-07-2008, 12:43 PM

Tags for this Thread

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