+ Reply to Thread
Results 1 to 40 of 40

Replace special character in whole column

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Replace special character in whole column

    Hello everyone

    I am trying the code
    Please Login or Register  to view this content.
    This doesn't work for whole column although when looping through each cell and using Replace it works with each cell
    Is there a way to make that works on the whole column.. I tried putting the character ~ before the character but doesn't work too

    I even tried usign Chr(220) but doesn't work too
    Please Login or Register  to view this content.
    I also tried using ChrW but doesn't work too
    Please Login or Register  to view this content.
    Posted at this link too
    https://www.eileenslounge.com/viewto...p?f=30&t=33708
    https://chandoo.org/forum/threads/re...-column.43145/
    Last edited by YasserKhalil; 11-30-2019 at 11:24 AM.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Replace special character in whole column

    Don't know. This worked for me.
    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Thanks a lot. I tried but didn't work for me.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi Yasser,

    check the ASCII code (the wide one) …

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Quote Originally Posted by Marc L View Post
    Hi Yasser,

    check the ASCII code (the wide one) …
    More details please Mr. Marc

  6. #6
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Replace special character in whole column

    Place a sample file with cells where things are going well and cells where things are not going well.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Here's sample file
    Attached Files Attached Files

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Replace special character in whole column

    There are actually 5 characters making up what appear to be space hyphen space ( or t ـــ F ) between the words "lot" and "For" in your example. The 3 "hyphens" in the middle all give an ASCII code of 63 using the CODE function, so this is clearly wrong. I carefully copied the text t ـــ F from one of the strings into cell D2, and this formula:

    =SUBSTITUTE(B2,D$2,"t F")

    was able to remove the offending characters, so maybe you need to be more careful in copying that bit of text into your

    What:="ـــ",

    part of the statement.

    Hope this helps.

    Pete

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Thank you very much Mr. Pete
    I recognize using SUBSTITUTE and I have tested that before .. Also used Replace for each cell in the range ( this approach worked fine)
    What is not working is the replace for the whole range and I don't know why doesn't work although it is working for any other characters..

  10. #10
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Replace special character in whole column

    I just used the SUBSTITUTE function as it is quicker for me.

    Maybe those cells for which it doesn't work have a slightly different set of characters in them, so you might have to use two or more Replace statements.

    Hope this helps.

    Pete

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Do you mean to repeat the same code more than once ..?
    if so I already did that but this doesn't let me get the desired output
    The only and most solution that works very fine till now is this code (Fluff's code on Chandoo)
    Please Login or Register  to view this content.
    Which used the same logic as yours ..

  12. #12
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Replace special character in whole column

    Take a look at the attached file. All the entries in column B look the same, but the formula in column C does not get rid of the "hyphen" in C4. That is because I amended the entry in B4 so that it has 4 "hyphens" instead of 3, and so the formula doesn't change it on that line. What I am suggesting is that you might have some entries like this, which might look the same but which have a different number of those "hyphen" characters in them.

    So, if you have a mixture of 3 and 4 "hyphens" you will need to have your Replace statement repeated, one for 3 and another for 4 "hyphens".

    Alternatively, you could just have a single "hyphen" in your code, although your little macro seemed to have an underscore character, which is not the same (note also that you would end up with a double-space if you just got rid of the "hyphens"). I couldn't copy the hyphen character directly into your code, so maybe you could copy it carefully to a cell on the sheet, and refer to that cell in the What:= part of your statement.

    Hope this helps.

    Pete
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    @Pete
    That's not hyphen at all. This is a special Arabic character that is produced when typing Arabic
    I press the Shift Key then type the letter J (this produces this character)

  14. #14
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Replace special character in whole column

    Or with a macro. I can't manage without a loop.

    Please Login or Register  to view this content.

  15. #15
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Thanks a lot. It seems no way of escaping the loop.
    The only way is to use Evaluate approach

    ** In the loop it is just sufficient and more flexible to use
    Please Login or Register  to view this content.
    Last edited by YasserKhalil; 11-30-2019 at 12:54 PM.

  16. #16
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Replace special character in whole column

    I know it is not a hyphen - that's why I put quotes around the word. It just looks a bit like a hyphen to me in a UK version.

    Pete

  17. #17
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Replace special character in whole column

    Already posted this in Chandoo, but this seems to work.
    Please Login or Register  to view this content.

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Thanks a lot again but this doesn't work for me
    In real file there are no spaces before this character .. It seems like that
    بـــــســـــم الله الــــرحـــمــــن الــــرحــــيـــــم

    The character is in between the other characters without spaces
    The desired result is
    بسم الله الرحمن الرحيم

  19. #19
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Replace special character in whole column

    You're quite right. I was 'playing' with the variable x in combination with Unichar

  20. #20
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Replace special character in whole column

    @YasserKhalil - You posted using Chr(220), but Chr(95) is the ASCII subscript symbol

    Please Login or Register  to view this content.

  21. #21
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Replace special character in whole column

    Quote Originally Posted by YasserKhalil View Post
    ... but this doesn't work for me ...


    As above JLGWhiz wrote and ...
    try to provide yourself some time, something to drink and eat ... and to work ... 65535 cells to review ...

    Please Login or Register  to view this content.

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

    Re: Replace special character in whole column

    Please Login or Register  to view this content.

  23. #23
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Thanks a lot everybody for sharing
    @Jindon
    Thank you very much. I tested the code and nothing changed as for me. The character is represented using ChrW(1600), how about 8204?

  24. #24
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Replace special character in whole column

    Please Login or Register  to view this content.
    Ben Van Johnson

  25. #25
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Thanks a lot Ben for sharing
    The same ideas discussed and all are working ..

    The target of the thread is to know why this character specially doesn't work when replacing in the whole column like any other character .. and is there any workaround to do that using the same technique of using the code in the same way as Jindon offered ..

  26. #26
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Replace special character in whole column

    The 'Why" is simple enough. The symbol in the code is not the same as the symbol on the worksheet. Have you tried copying the symbol on the sheet into the 'Replace' statement in the code to see if it will then execute the replacement? There are multiple unicode values for look alike symbols of the subscript. Without knowing from where the symbol originated and what code the originator was using, it could be any of several code values that created the symbol.

  27. #27
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    The character is produced when typing Arabic. I press Shift + J letter >> this is how the character generated ..
    I tried to replace the character manually and this doesn't work too

  28. #28
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Replace special character in whole column

    Quote Originally Posted by YasserKhalil View Post
    ... to know why this character specially doesn't work when replacing ...
    Trivially speaking, this is "normal". It is caused by different code pages in computer systems, different character encoding (single-byte, double-byte, etc.), various character separation systems, etc.
    We often see the manifestations of "such behavior", e.g. for: Val, CDbl, CDate, DateValue, ... (etc. ?).

    I saw a similar case with the symbol "?" in 'EXIF' metadata.
    It turned out that this symbol, at the same time, is and is not this symbol.

    If I didn't make any mistake, this can be traced in the code below.
    This is a short code (for the attached photo):
    Please Login or Register  to view this content.
    that acquires the date the picture was taken (Date taken).

    It is not known why the result is a string like: srcdat = "?30-?05-?2008 ??15:56"
    When you start to check these "?" symbols, they turn out to be "strange things".

    InStr(1,srcdat, "?", 1) => gives '0'
    InStr(1,srcdat, Chr(63), 1) => gives '0'
    Replace(srcdat, "?", "", 1, -1, 1) => nothing happens
    Replace(srcdat, Chr(63), "", 1, -1, 1) => nothing happens

    When: vchar = Mid(srcdat, i, 1), where i = 1, 2, 3, etc., then:

    For: vchar = "?"
    Statement: If vchar = "?" Then when_True Else when_False => gives FALSE
    But statement: If Asc(vchar) = 63 Then when_True Else when_False => gives TRUE
    At the same time: AscW(vchar) => gives 8206 or 8207 depending on the location of the symbol "?"

    Unicode 8206 and 8207 visually are invisible symbols.

    Nothing is what it seems to be.

    Workaround ?
    First: identification of symbols/characters.
    The rest depends on the object being processed.

  29. #29
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,230

    Re: Replace special character in whole column

    !!!!!!!!!!!!!!!!!!!!!!Deleted!!!!!!!!!!!!!!!!!!!!
    Last edited by sintek; 12-01-2019 at 02:01 PM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  30. #30
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Replace special character in whole column

    Quote Originally Posted by YasserKhalil View Post
    ... I tried to replace the character manually and this doesn't work too ...
    Are you sure that this symbol/symbols ( _ ) are redundant/excess symbols, not created as a result of "stretching" the text/letters ?

  31. #31
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Replace special character in whole column

    @porucha vevrku - I wonder if the anomally you describe in post #28 might be caused by exclusion of the relevant code in the underlying software that drives VBA, Excel and even the compiler. Maybe I am reaching too far for some kind of logic that would explain this phenomenon, but there has to be something that can explain how the item can be created but not destroyed.

  32. #32
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Replace special character in whole column

    It can be removed in Excel (see post#11), but not with VBA.
    So it seems that xl & vba interpret that symbol differently for some reason

  33. #33
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Replace special character in whole column

    Quote Originally Posted by Fluff13 View Post
    It can be removed in Excel (see post#11), but not with VBA.
    So it seems that xl & vba interpret that symbol differently for some reason
    It is the zeros and ones being in different locations, but why? Bill Gates strikes again!!!

  34. #34
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Replace special character in whole column

    Quote Originally Posted by YasserKhalil View Post
    ... It seems like that
    بـــــســـــم الله الــــرحـــمــــن الــــرحــــيـــــم
    ...
    The desired result is
    بسم الله الرحمن الرحيم
    Maybe "it" ( ChrW(1600) ) to change/remove somehow this way ?

    Although it is not "all at once", but cell by cell only, but we can keep trying further.

    'B1' = بـــــســـــم الله الــــرحـــمــــن الــــرحــــيـــــم

    Please Login or Register  to view this content.
    Last edited by mjr veverka; 12-01-2019 at 05:45 PM.

  35. #35
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Replace special character in whole column

    Quote Originally Posted by JLGWhiz View Post
    ... might be caused by exclusion of the relevant code in the underlying software that drives VBA, Excel and even the compiler ...
    Maybe, I don't know ...
    Below is a recorded screenshot with the code running and a text file with messages from 'Debug.Print'.
    A screen recording made with a some small program, gave a large result file, so I had to pack it into three zip files.
    I added the '.zip' extension to the name of each zip file to be able to upload the file to the forum, so, it must be removed before unpacking.


    Edit:

    I replaced the zip archive with a new one
    Last edited by mjr veverka; 12-02-2019 at 08:16 AM.

  36. #36
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Quote Originally Posted by porucha vevrku View Post
    Are you sure that this symbol/symbols ( _ ) are redundant/excess symbols, not created as a result of "stretching" the text/letters ?
    Yes you are right. The symbols are stretched three times
    Please Login or Register  to view this content.
    This is the symbol
    And I will attach a file with the symbol just in one cell A1
    Attached Files Attached Files

  37. #37
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    As for the files in post #35, the archive is corrupt
    You can upload the file to external link

  38. #38
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Replace special character in whole column

    Ok, I edited post

  39. #39
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Replace special character in whole column

    Thank you very much for great help in this issue. I have learned a lot from you

  40. #40
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Replace special character in whole column

    You're welcome - these are mutual benefits.
    Without some topics, there would be no solutions/no attempts at solutions, no other look at things that seemed familiar to us, trite, there would be no learning, self-study, etc ... and to you, a well-known person ..., already wrote that you have attention-grabbing topics.

+ 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. [SOLVED] how to find special character & replace with blank
    By mohan.r1980 in forum Excel General
    Replies: 7
    Last Post: 08-31-2016, 12:30 PM
  2. Replace special character
    By winmaxservices in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-18-2016, 12:48 AM
  3. Need to highlight special character and the cells contains special character
    By dhilipan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-26-2013, 01:36 AM
  4. How to vlookup a Column contain special character and replace it?
    By miraclesuki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2013, 05:03 PM
  5. to find and replace the special character in multiple worksheet in a workbook
    By Vinutha in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-11-2012, 11:16 AM
  6. How to replace special character (square box) in cell
    By anilk.zee in forum Access Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2012, 03:17 PM
  7. How to replace special character (square box) in cell
    By anilk.zee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2012, 12:10 PM

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