Subtitute contents from one cell into another

davidmg1982

Board Regular
Joined
Oct 12, 2015
Messages
64
Morning everyone, i will appreciate your help to elaborate a Subroutine or UDF to substitute/delete all the words from cell B1 into cell A1, showing the result in cell C1, example:
B1 may have more than one word, all separated by comma + space ", "
[TABLE="width: 836"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]A1[/TD]
[TD]B1[/TD]
[TD]C1[/TD]
[/TR]
[TR]
[TD]ALTEA NOTIFICATION HDQQFLR006 FILESYSTEM VOL XLQCHANNELAPI34 OVER[/TD]
[TD]HDQQFLR006, XLQCHANNELAPI34[/TD]
[TD]ALTEA NOTIFICATION FILESYSTEM VOL OVER[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

thanks in advance for your guidance!
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
This macro should work for as many rows of data that you have.
Code:
Sub davidmg1982()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    Dim splitRng As Variant
    Dim i As Long
    For Each rng In Range("B1:B" & LastRow)
        splitRng = Split(rng, ", ")
        For i = LBound(splitRng) To UBound(splitRng)
            rng.Offset(0, -1) = Replace(rng.Offset(0, -1), splitRng(i), "")
        Next i
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
This macro should work for as many rows of data that you have.
Code:
Sub davidmg1982()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    Dim splitRng As Variant
    Dim i As Long
    For Each rng In Range("B1:B" & LastRow)
        splitRng = Split(rng, ", ")
        For i = LBound(splitRng) To UBound(splitRng)
            rng.Offset(0, [B][COLOR="#FF0000"][SIZE=4]-1[/SIZE][/COLOR][/B]) = Replace(rng.Offset(0, -1), splitRng(i), "")
        Next i
    Next rng
    Application.ScreenUpdating = True
End Sub
Shouldn't the red highlighted -1 actually be +1 ?
 
Last edited:
Upvote 0
Thank you Rick. You are absolutely correct. :)
 
Upvote 0
This macro should work for as many rows of data that you have.
Code:
Sub davidmg1982()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    Dim splitRng As Variant
    Dim i As Long
    For Each rng In Range("B1:B" & LastRow)
        splitRng = Split(rng, ", ")
        For i = LBound(splitRng) To UBound(splitRng)
            rng.Offset(0, -1) = Replace(rng.Offset(0, -1), splitRng(i), "")
        Next i
    Next rng
    Application.ScreenUpdating = True
End Sub


AMAZING, thank you so much for sharing your knowledge.
 
Upvote 0
You are very welcome. :) And thanks to Rick for picking up on my error.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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