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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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