Results 1 to 9 of 9

Thread: unwanted symbol

  1. #1

    Thread Starter
    Lively Member yanty's Avatar
    Join Date
    Nov 2005
    Location
    Singapore
    Posts
    83

    unwanted symbol

    I am currently exporting data to an excel worksheet.

    One of the data consist an address field which when exported to excel, will be in a multi line order. eg.

    vba building
    22 new york street
    new york 122655

    but the problem is that beside name of building, address and postal code will appear a square symbol (i'm guessing its becos of the enter key which allows multiline data). tried to do the replace function to replace the square with a blank, but it didnt work, squares still visible.

    anyone know how to make the square box dissapear?
    I think I'm starting to like programming, but I'm still far from good

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: unwanted symbol

    You could use the excel CLEAN function, which will remove all non-printable character.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Lively Member yanty's Avatar
    Join Date
    Nov 2005
    Location
    Singapore
    Posts
    83

    Re: unwanted symbol

    could you give me an example where can i put the clean function?
    I think I'm starting to like programming, but I'm still far from good

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: unwanted symbol

    VB Code:
    1. Sub CleanExample()
    2. Dim rngAreaToClean As Range
    3. Dim rngMyCell As Range
    4.    
    5.     'Whatever range you need to clean
    6.     Set rngAreaToClean = ThisWorkbook.Worksheets(1).UsedRange
    7.    
    8.     'Loop through each cell
    9.     For Each rngMyCell In rngAreaToClean.Cells
    10.        
    11.         With rngMyCell
    12.            
    13.             'Removing non-prinable characters
    14.             .Value = Application.WorksheetFunction.Clean(.Value)
    15.            
    16.         End With
    17.        
    18.     Next rngMyCell
    19. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: unwanted symbol

    Hi Declan,

    Thanks for this Great code!

    But, I would like to know what the non-printable characters this code will remove?
    CS

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: unwanted symbol

    I believe that it will remove all nonprintable characters,
    LF, CR NBSP, etc
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: unwanted symbol

    I also encounter the "squares" problem from time to time in Excel 2003 and thought this CLEAN function would be of real use. However, when I applied it, it also brought the second line of any cells containing multiline text back to the first .

    For example, a table header (cell) with the title:

    Total
    Mass

    was changed to:

    TotalMass
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  8. #8
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: unwanted symbol

    Yes! it happend to me also. How can we get around of this problem.

    Is there any equivalent code in vb6? (not using excel)
    CS

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: unwanted symbol

    A carriage return or Enter key is a non-printable character. So when you use Clean it removes the line breaks and it will all appear on one line.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width