+ Reply to Thread
Results 1 to 9 of 9

Newline being ignored

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Newline being ignored

    I'm using Microsoft Query to retrieve data into Excel. I'm trying to build the SELECT statement so that it concatenates newline (carriage return) characters in the results, but the newline characters are being ignored. Yes, I have word wrap enabled, and the cell width is smaller than the data. I've tried multiple combinations of line feed (CHAR(10) or hex 0A) and form feed (CHAR(13) or hex 0D), but none of them work. I've tried all of these:

    SELECT TRIM(cnam05) || X'0D' || X'0A' ||  
    		TRIM(cad105) || X'0D' || X'0A' ||  
    		TRIM(cad205) || X'0D' || X'0A' ||  
    		TRIM(cad405) || X'0D' || X'0A' ||  
    		TRIM(cad505) as "Customer Address",
    SELECT TRIM(cnam05) || X'0A' || X'0D' ||  
    		TRIM(cad105) || X'0A' || X'0D' ||  
    		TRIM(cad205) || X'0A' || X'0D' ||  
    		TRIM(cad405) || X'0A' || X'0D' ||  
    		TRIM(cad505) as "Customer Address",
    SELECT TRIM(cnam05) || X'0A' ||  
    		TRIM(cad105) || X'0A' ||  
    		TRIM(cad205) || X'0A' ||  
    		TRIM(cad405) || X'0A' ||  
    		TRIM(cad505) as "Customer Address",
    SELECT TRIM(cnam05) || X'0D' ||  
    		TRIM(cad105) || X'0D' ||  
    		TRIM(cad205) || X'0D' ||  
    		TRIM(cad405) || X'0D' ||  
    		TRIM(cad505) as "Customer Address",
    All of the above create the same results: a concatenated address, like this:

    MY CUSTOMER123 MAIN STSOMETOWN NY

    I need the results to look like this:

    MY CUSTOMER
    123 MAIN ST
    SOMETOWN
    NY

    I can easily accomplish the above with a VBA macro. But I'd like to know how to resolve this "newline issue" with just a query.

    Any suggestions?

    Oh, and I've googled the hell out of this issue. I found lots of suggestions for Ctrl+Enter and formulas, but those don't apply to my issue.

    TIA

    Tom

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Newline being ignored

    What is the source database (i.e. what type of database is it, Access, Oracle, SQL, Excel Workbook etc)?

  3. #3
    Registered User
    Join Date
    01-10-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Newline being ignored

    DB2 for i (IBM's silly name for the database on the AS400/iSeries)

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Newline being ignored

    Oh, I forgot to mention that when query is loaded to sheet, you'll have to double click on cell to make CHR(13) active (SQL or most db does not display CHR(13) within field).

    Sample query.
    SELECT Trim(cnam05)+CHR(13)+
    	Trim(cad105)+CHR(13)+
    	Trim(cad205)+CHR(13)+
    	Trim(cad405)+CHR(13)+
    	Trim(cad505) AS 'caddress'
    FROM `C:\Test\Source.xlsx`.`Sheet1$` `Sheet1$`
    It will initially display as...
    0.JPG

    Double click on the cell.
    1.JPG

    Edit: If you want to apply to multiple rows, just copy format of first cell and apply to rest.
    Last edited by CK76; 08-23-2018 at 11:44 AM.

  5. #5
    Registered User
    Join Date
    01-10-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Newline being ignored

    Interesting. Either Excel version 1803 (from Office 365) behaves differently, or retrieving from DB2 instead of Excel behaves differently.

    I changed my query to use CHR(13), just like your example, and I get the same results. Double-clicking in a cell merely puts me in Edit mode for the cell contents - it does not change or expand the newline characters.

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Newline being ignored

    What happens if you double click or go to Formula bar. And then remove focus (click out or tab out)?

    This should be when CHR(13) is applied.

  7. #7
    Registered User
    Join Date
    01-10-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Newline being ignored

    Same results - CHR(13) still does not get applied.

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Newline being ignored

    Hmm, are you able to do the job from DB2 side? Use job(s) to export to csv or some other file type. Then import the file into Excel.
    This should accurately reflect carriage return/new line character.

    If not, I'm out of ideas.

  9. #9
    Registered User
    Join Date
    01-10-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Newline being ignored

    No, I'll just rewrite the process as a macro.

    I was just hoping to find a workaround for another Excel oddity. It would be nice to be able to write queries that can combine address information into one cell. But since XL won't cooperate, I'll just write a macro.

    Thanks for trying.

    Tom

+ 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] Insering newline at every space
    By mandukes in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-06-2013, 06:18 AM
  2. How to replace space with newline
    By utpalmtbi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-11-2013, 09:13 PM
  3. [SOLVED] newline in a textbox vba
    By Mimouscha in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2013, 11:01 AM
  4. Search / Replace with NewLine
    By drew138 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-11-2009, 08:42 PM
  5. newline in cells - inconsistent behavior
    By irwinhorowitz in forum Excel General
    Replies: 0
    Last Post: 04-28-2008, 03:43 PM
  6. Newline inside a Cell
    By anandmr65 in forum Excel General
    Replies: 1
    Last Post: 09-29-2006, 01:31 AM
  7. [SOLVED] Returning newline from a function to a cell
    By Dave Dixson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2006, 08:25 AM
  8. newline in a msgbox
    By greenjellystar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-10-2005, 12:06 PM

Tags for this Thread

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