+ Reply to Thread
Results 1 to 7 of 7

Remove trailing commas

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    95

    Remove trailing commas

    Column Programs are the results of concatenated cells with commas. I need to be able to remove all commas at end of each cell. I cant seem to use find and replace functions.

    Thanks
    Attached Files Attached Files

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Remove trailing commas

    In your file, I highlighted the data in column B,
    used CTRL H (find/replace)
    Find ,
    Replace (nothing - leave blank)

    \It worked fine for me?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Remove trailing commas

    If you've got intermediate commas but you only want to remove any end commas, then if you'd also like a VBA approach, maybe:
    Sub uuu()
    
    Dim a, c, x
    a = Range("B1", Cells(Rows.Count, "b").End(3))
    
    For Each x In a
        c = c + 1
        Do
            If Right(Trim(x), 1) = "," Then x = Left(x, Len(x) - 1) Else Exit Do
        Loop
        a(c, 1) = x
    Next x
    
    Range("B1", Cells(Rows.Count, "b").End(3)) = a
    
    End Sub

  4. #4
    Registered User
    Join Date
    05-23-2016
    Location
    Chicago, Illinois
    MS-Off Ver
    2010
    Posts
    3

    Re: Remove trailing commas

    Thank you for this. I just posted the same question

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Remove trailing commas

    FWIW:

    Sub danallamasy()
    Dim x As Range
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With
    For Each x In Range("B1:B" & Range("B" & Rows.Count).End(3).row)
       If Right(x, 2) = ", " Then
        With x
            Do Until Right(x, 1) <> " " And Right(x, 1) <> ","
                   x = Left(x, Len(x) - 1)
            Loop
        End With
        End If
    Next x
    With Application
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
    End With
    End Sub

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Remove trailing commas

    This should do
    Sub test()
        Dim a, i As Long
        With Range("b2", Range("b" & Rows.Count).End(xlUp))
            a = .Value
            With CreateObject("VBScript.RegExp")
                .Pattern = "(, *)+$"
                For i = 1 To UBound(a, 1)
                    a(i, 1) = .Replace(a(i, 1), "")
                Next
            End With
            .Value = a
        End With
    End Sub

  7. #7
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Remove trailing commas

    Not sure what is going on.. but can't post my solution.. keep getting some firewall message..

    Found a thread in the Water Cooler about it.. but nothing i do will allow me to post the code i made..
    Attached Images Attached Images
    Last edited by apo; 06-15-2015 at 09:43 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 11-23-2016, 12:22 PM
  2. Concatenate cell Title and remove trailing commas using Excel VB
    By missit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-23-2013, 12:36 AM
  3. Replies: 5
    Last Post: 11-26-2012, 08:44 AM
  4. Macro, to remove commas and remove speach marks
    By 5h1l in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2012, 12:06 PM
  5. Extra trailing commas in exported CSV
    By lucidr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2006, 08:40 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1