VBA - Deleting a chain of characters specified in an another cell

Alex38

New Member
Joined
Jun 16, 2015
Messages
3
Hello,

I am looking for a VBA macro doing a specific job for which I am a bit struggling to code.

I have a table where there is a string of characters in a column (essentially codes or references), and then I find them again later in another column (here C), sometimes in disorder :

[TABLE="class: grid, width: 600"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Components codes[/TD]
[TD]Characteristics of the product[/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]8002, 75410, 1221,[/TD]
[TD]8002, 75410 and 1221, small, blue color[/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]3326, 84164, 2114, 1459[/TD]
[TD]3326, 84164, 1459, 2114 and only for export[/TD]
[/TR]
[TR]
[TD]Product 3[/TD]
[TD]7456, 4362[/TD]
[TD]7456, 4362, medium size, yellow, high quality certification[/TD]
[/TR]
</tbody>[/TABLE]

See the recurrence ?

So I would like to delete all the references appearing in column C because it is already populated in column B ... but without deleting the other characteristics.

My basic idea was taking one by one the codes (always separated by a comma) and then compare if it is present in Column C. If it is true, deleting the code in this Column C. And repeating this for every code in the cell and then every line.

But I don't know how to isolate in VBA the references that are in column B (the length of characters for the code is variable :/ )

Is it possible to have some help ? :)

Thank you :)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
See the use of the SPLIT statement
If cells(2,2) contains "8002, 75410, 1221"

AAA = Split(cells(2,2),",")
then
AAA(0) = "8002"
AAA(1) = "75410"
AAA(2) = "1221"
 
Upvote 0
A piece of code to help

Code:
Option Explicit

Sub Treat()
Dim LR  As Long, I  As Long
Dim Temp
Dim J  As Integer
    LR = Range("A" & Rows.Count).End(xlUp).Row
    For I = 2 To LR
        If (Cells(I, 2) <> "") Then
            Temp = Split(Cells(I, 2), ",")
            For J = 0 To UBound(Temp, 1)
                If (Temp(J) <> "") Then
                    Cells(I, 3) = Replace(Cells(I, 3), Temp(J) & ",", "")
                End If
            Next J
        End If
    Next I
End Sub
 
Upvote 0
Thanks a lot ! I didn't think about that Split function.

The formula you provided is great and flexible for others type of replacements.

Thanks again :)
 
Upvote 0

Forum statistics

Threads
1,223,640
Messages
6,173,501
Members
452,517
Latest member
SoerenB

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