Results 1 to 12 of 12
  1. #1
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Remove comma from cell content (2003)

    Dear All,

    Is there a way to search and remove "," (comma) that appears as last character of content in a table cell?

    Thank you in advance
    Ridz

  2. #2
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Remove comma from cell content (2003)

    If the comma is in a certain column in a table, you can select only that column and run a find/replace command finding a comma and replacing with nothing. (Leave replace blank). The replace will only take place in the selected column. At the end, choose NO when responding to "Do you want to continue with rest of doc" prompt.
    Regards,
    Rudi

  3. #3
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove comma from cell content (2003)

    Thanks Rudi,

    Unfortunately the case is not that simple. There are large amount of tables in different pages across 300+ pages. And to make things worse, that last comma is not the only comma in the table cell.

  4. #4
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Remove comma from cell content (2003)

    I have been testing the find string:
    >(*^44) or >(^44) or >, or >(,)...
    but cannot seem to get anyto work... It still finds ALLcommas in the string.
    I guess I am getting the codes wrong. <img src=/S/drop.gif border=0 alt=drop width=23 height=23>

    The find replace feaure is really powerful to replace many things, but this one has got me <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    Maybe a Word Guru can conjure up a macro to do the job.
    Regards,
    Rudi

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Remove comma from cell content (2003)

    Try this macro:

    Sub RemoveCommaFromEnd()
    Dim oTable As Table
    Dim oCell As Cell
    Dim oRange As Range
    Application.ScreenUpdating = False
    For Each oTable In ActiveDocument.Tables
    oTable.Select
    For Each oCell In Selection.Cells
    If Asc(Right(oCell.Range.Text, 3)) = 44 Then
    Set oRange = oCell.Range
    oRange.MoveEnd Unit:=wdCharacter, Count:=-1
    oRange.Characters.Last.Delete
    End If
    Next oCell
    Next oTable
    Application.ScreenUpdating = True
    End Sub

    Note: the code will not remove a comma if there is an empty paragraph after it (a mistake people often make in table cells); it could be expanded to take care of that too.

  6. #6
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Remove comma from cell content (2003)

    Hans,

    In your and otherw experienced in Word... Is there no way to do this with find/replace. I know I struggled as you can see in the previous post, but the > search character allows to search at the end of the word...so can this be tweeked in any way to do the job without that rather impressive macro you wrote?

    Cheers
    Regards,
    Rudi

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Remove comma from cell content (2003)

    I don't know what "your and otherw experienced in Word" is, but:
    - You don't know in advance which word is the last word in a cell, so I don't see how you could use >.
    - There is no code you can use in the Find/Replace dialog to find the end-of-cell marker.

  8. #8
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Remove comma from cell content (2003)

    Sorry... I meant "In your or others opinion who are experienced in Word"...

    I hear what you say, but the > search character is used like a input mask character to find a character at the end of the word. Hence me trying (,)>
    This is what Word help has to say:
    <pre>To find Type Example
    Any single character ? s?t finds sat and set.
    Any string of characters * s*d finds sad and started.
    The beginning of a word < <(inter) finds interesting and intercept, but not splintered.
    The end of a word > (in)> finds in and within, but not interesting.
    </pre>


    It works in the example, but not for a comma. My only assumption is that it only works for alpha chars and numbers. ? That is why I tried the ascii codes (^44).
    Regards,
    Rudi

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Remove comma from cell content (2003)

    A "word" is a series of characters delimited by interpunction such as a space, comma, period, colon, semicolon, question mark, exclamation mark, paragraph end and no doubt others. Hence, a comma is not part of a word.

    But once again, even if you could find a comma at the end of a word, how would that help? There could also be a comma at the end of a word in the middle of a cell, and you wouldn't want to remove that. So there is no point in trying to use > here.

  10. #10
    3 Star Lounger
    Join Date
    Feb 2003
    Location
    Runcorn, Cheshire, United Kingdom
    Posts
    372
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Remove comma from cell content (2003)

    Can we assume that all commas (other than the last comma in a cell) are followed by a space?
    In which case we do a 3 stage change
    Find ', ' (Comma Space) and replace with '!#' (or some similar unique combination)
    Find ',' (Comma) and replace with '' (empty string)
    Find ''!#' and replace with ', ' (Comma Space)

  11. #11
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Remove comma from cell content (2003)

    Ok...this is more clearer. I have it now.
    TX Hans and Gfamily.
    Regards,
    Rudi

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Remove comma from cell content (2003)

    That is a clever thought, but the assumption could be dangerous - what if there are numbers such as 12,345.67?
    Also, the original poster mentioned that this is a long document with many tables. A Replace All would work throughout the document (not only in tables). Selecting each table in turn, then replacing within the selection only becomes tedious after a while.
    The macro I posted will loop through all tables in the document, it doesn't affect other parts of the document.

Posting Permissions

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