Results 1 to 7 of 7

Thread: [RESOLVED] Carriage returns and Text Format

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] Carriage returns and Text Format

    Hey,

    I am populating a spreadshhet from a database query but am having problems making the text look correct.

    In the 3rd column you can see that whilst the text in the cells starts a new line it also appears to have "|" or a symilar symbol, what would be the best way of getting rid of this.

    In addition some lines just appear as "#####" which I also dont know why.

    I would also like to have a button which allows the user to decide whether the text is displayed along one line or if the text in a cell goes over more and the cell expands.

    Any help on the following would be appreciated.
    Attached Images Attached Images  

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Carriage returns and Text Format

    Can you upload a sample of the excel file for a quick resolution?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Carriage returns and Text Format

    In addition some lines just appear as "#####" which I also dont know why.
    generally a number longer than will display in the cell

    the | is probably a vbcr (chr(13))
    so you should replace vbcrlf with vblf (chr(10))
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Carriage returns and Text Format

    Attached a workbook with the problem.

    Is it worth mentioning that as the data is put into a record set before drwan onto the workbook, it may be possible to apply a fix either bofore or after the data is being displayed.

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Carriage returns and Text Format

    workbook missing...

    You might have to zip it and then attach it...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Carriage returns and Text Format

    1. Line-feed character:
    Excel use Chr(10) = vbLf to break lines in cells. Your database such as Access uses vbCrLf = Chr(13) & Chr(10) for line-breaks.
    The "bar" (with font size < 8) or a "square box" (with font size >=8) represents Chr(13) = vbCr.

    * You have to remove Chr(13) in data from database before populating it to Excel.
    sFieldText = Replace(sFieldText, vbCr, "")
    or
    sFieldText = Replace(sFieldText, vbCrLf, vbLf)
    or
    * After populating use this worksheet formula: =SUBSTITUTE(D2,CHAR(13),"")

    2. The text is displayed as ####################################:
    When a cell has been formatted as Text (with NumberFormat = "@"), if the cell contains more than 255 characters then it will be displayed like that even you make the cell very wide and/or very high.

    * To fix that: Change the "NumberFormat" of the cell to "General".
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  7. #7

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Carriage returns and Text Format

    Quote Originally Posted by anhn View Post
    1. Line-feed character:
    Excel use Chr(10) = vbLf to break lines in cells. Your database such as Access uses vbCrLf = Chr(13) & Chr(10) for line-breaks.
    The "bar" (with font size < 8) or a "square box" (with font size >=8) represents Chr(13) = vbCr.

    * You have to remove Chr(13) in data from database before populating it to Excel.
    sFieldText = Replace(sFieldText, vbCr, "")
    or
    sFieldText = Replace(sFieldText, vbCrLf, vbLf)
    or
    * After populating use this worksheet formula: =SUBSTITUTE(D2,CHAR(13),"")

    2. The text is displayed as ####################################:
    When a cell has been formatted as Text (with NumberFormat = "@"), if the cell contains more than 255 characters then it will be displayed like that even you make the cell very wide and/or very high.

    * To fix that: Change the "NumberFormat" of the cell to "General".
    Thanks,

    as this is for a single report I have adapted your idea to the SQL layer as below, this has removed the funny lines.

    I also changed the Numberformat to General to remove the hashes.

    Now I just need to provide a button which can change the sheet or range to wraptext.
    REPLACE(Common.tblAudit.[parameters],Char(13),'')

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