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.
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.
![]()
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
- Copy the Excel VBA code
- Select the workbook in which you want to store the Excel VBA code
- Press Alt+F11 to open the Visual Basic Editor
- Choose Insert > Module
- Edit > Paste the macro into the module that appeared
- Close the VBEditor
- Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
To run the Excel VBA code:
- Press Alt-F8 to open the macro list
- Select a macro in the list
- Click the Run button
Ben Van Johnson
Solves my issue. Thanks for the answer its appreciated.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks