Remove text from a cell that is contained in other multiple cells

Rick73

New Member
Joined
Jun 8, 2018
Messages
2
Hi all,

I am hoping that somebody can show me the easiest way to accomplish deleting the values in multiple cells from another cell. I thought it would be an easy SUBSTITUTE with "", but nothing I am writing works. It will obviously need a more elegant VBA solution.

From the table below I am using a common list of names, each name is separated with a carriage return (A1). For each row (2,3,4), I am trying to remove the names in the cells from column A, B, C from the list of names in A1 and display the remaining names in column E.
ABCDE
1SURNAME Name 1
SURNAME Name 2
SURNAME Name 3
SURNAME Name 4
SURNAME Name 5
SURNAME Name 6
SURNAME Name 7
SURNAME Name 8
RESULT
2SURNAME Name 5SURNAME Name 2
SURNAME Name 3
SURNAME Name 7
SURNAME Name 1
SURNAME Name 4
SURNAME Name 6
SURNAME Name 8
3SURNAME Name 4
SURNAME Name 3
SURNAME Name 8SURNAME Name 2SURNAME Name 1
SURNAME Name 5
SURNAME Name 6
SURNAME Name 7
4SURNAME Name 2
SURNAME Name 7
SURNAME Name 1
SURNAME Name 8
SURNAME Name 3
SURNAME Name 4
SURNAME Name 5
SURNAME Name 6
5

<tbody>
</tbody>

Sounds simple but it is a little bit beyond my skills at the moment. I would greatly appreciate any help or code.

Regards
Rick73
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub ReduceSurnameList()
  Dim R As Long, X As Variant, NameList As String, CheckNames() As String
  For R = 2 To Cells(Rows.Count, "A").End(xlUp).Row
    NameList = vbLf & Range("A1").Value & vbLf
    CheckNames = Split(Join(Application.Index(Cells(R, "A").Resize(, 3).Value, 1, 0), vbLf), vbLf)
    For X = 0 To UBound(CheckNames)
      NameList = Replace(NameList, vbLf & CheckNames(X) & vbLf, vbLf)
    Next
    For Each X In Split("121 13 5 3 3 2")
      NameList = Replace(NameList, vbLf & vbLf, vbLf)
    Next
    Cells(R, "E").Value = Mid(NameList, 2, Len(NameList) - 2)
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Thanks for your reply Rick

Sensational! Exactly how I would have coded it if I had the skill. Works perfectly.

Regards
Rick73
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,728
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top