+ Reply to Thread
Results 1 to 3 of 3

Identify changes to text

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2014
    Location
    Wgtn NZ
    MS-Off Ver
    Excel 2010
    Posts
    17

    Identify changes to text

    I have Names in two columns. Column A has the original name and column B has the name after it has been changed. In column C I want the change made to appear.

    See attached sample.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    13,035

    Re: Identify changes to text

    Option Explicit
    Sub comparestrings()
        Dim NameParts   As Variant, _
            Name1       As String, _
            Name2       As Range, _
            Name2List   As Range, _
            Ndx         As Long, _
            Results     As String
            
        With Sheets("sheet1")
            Ndx = .Cells(Rows.Count, 3).End(xlUp).Row
            
            'dimension the block of names in column C
            Set Name2List = .Range("C2").Resize(Ndx - 1)
            
            'Go down the list of changes
            For Each Name2 In Name2List
                Results = ""
                
                'copy old name for testing
                Name1 = Name2.Offset(0, -1).Value
                
                'break-up the new name into separate elements of an array
                NameParts = Split(Name2)
                            
                For Ndx = 0 To UBound(NameParts)
                
                    'search the old name for each element of the new name
                    If InStr(Name1, NameParts(Ndx)) = 0 Then
                    
                        'if the part is not found, add it to the results string
                        Results = Results & NameParts(Ndx) & " "
                    End If
                Next Ndx
                
                'write the results to the sheet
                Name2.Offset(0, 1).Value = Results
                Erase NameParts
                
            Next Name2
        End With
            
    End Sub


    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    02-22-2014
    Location
    Wgtn NZ
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Identify changes to text

    Solves my issue. Thanks for the answer its appreciated.

+ 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. Formula to identify part of a text in cell from range of cells & insert adjacent cell text
    By Novicebutnotforlong in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-19-2013, 02:11 AM
  2. [SOLVED] TEXT Formula to identify rows of cells with Matching TEXT *** Actual Worksheet attached.
    By steve08087 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-29-2013, 12:42 PM
  3. Replies: 2
    Last Post: 05-09-2012, 11:22 PM
  4. Trying to identify if range contains text or not
    By henboffman in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-06-2011, 09:57 AM
  5. Identify text in uppercase
    By David in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-03-2005, 07:07 PM

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