Consulting

Results 1 to 6 of 6

Thread: Delete after coma when spicify workd does not exists

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Delete after coma when spicify workd does not exists

    Hello I have about 12000 row like these data and i need a VBA to remove the data between comma that the Volvo word does not exist mean

    A30D Volvo, A30E Volvo, A30F Volvo, A30F Volvo, A35D Volvo, A40D Volvo, 11038734, 11145211, 17236991
    A30D Volvo, A30E Volvo, A30F Volvo, A30F Volvo, A35D Volvo, A40D Volvo, 11038806, 17218651
    A30D Volvo, A35D Volvo, A40D Volvo, 11036695
    Will be like This :

    A30D Volvo, A30E Volvo, A30F Volvo, A30F Volvo, A35D Volvo, A40D Volvo
    A30D Volvo, A30E Volvo, A30F Volvo, A30F Volvo, A35D Volvo, A40D Volvo
    A30D Volvo, A35D Volvo, A40D Volvo
    Please help me if you can

  2. #2
    Try this code
    Sub Test()
        Dim a, x, s As String, i As Long, j As Long
        
        a = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Value
        
        For i = LBound(a) To UBound(a)
            x = Split(a(i, 1), ", "): s = ""
            For j = LBound(x) To UBound(x)
                If InStr(x(j), "Volvo") > 0 Then
                    s = s & IIf(s = "", "", ", ") & x(j)
                End If
            Next j
            a(i, 1) = s
        Next i
        
        Range("B1").Resize(UBound(a, 1), UBound(a, 2)).Value = a
    End Sub

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    I couldn't even wake up after my coma....

  4. #4
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Really appreciate for your help ! working great !

  5. #5
    You're welcome. Glad I can offer some help

  6. #6
    @ snb
    Were you sleep deprivied

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •