+ Reply to Thread
Results 1 to 3 of 3

Returning newline from a function to a cell

  1. #1
    Dave Dixson
    Guest

    Returning newline from a function to a cell

    I am trying to create a function that returns a string with a newline,
    which when shown in a cell forces the cell to show on muliple lines as
    if alt+enter was pressed.

    Here is a test function I have tried....

    Public Function getString() As String
    getString = "hello" & vbLf & "worl"
    end function

    Unfortunatly, when I reference this function from within a cell in
    excel it does not have the desired effect - it shows the new line as an
    uprintable character (a rectangle appears in the cell), and the whole
    string is shown on one string.

    Anyone know what characters I should return from my function to get it
    to display as a soft return in the cell?

    Cheers,

    Dave.


  2. #2
    Bob Phillips
    Guest

    Re: Returning newline from a function to a cell

    Public Function getString() As String
    getString = "hello" & Chr(10) & "world"
    End Function


    you will need to set wrap text on the cell as well

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Dave Dixson" <dave.dixson_nospam@bigfoot.com> wrote in message
    news:1156236574.618943.89170@74g2000cwt.googlegroups.com...
    > I am trying to create a function that returns a string with a newline,
    > which when shown in a cell forces the cell to show on muliple lines as
    > if alt+enter was pressed.
    >
    > Here is a test function I have tried....
    >
    > Public Function getString() As String
    > getString = "hello" & vbLf & "worl"
    > end function
    >
    > Unfortunatly, when I reference this function from within a cell in
    > excel it does not have the desired effect - it shows the new line as an
    > uprintable character (a rectangle appears in the cell), and the whole
    > string is shown on one string.
    >
    > Anyone know what characters I should return from my function to get it
    > to display as a soft return in the cell?
    >
    > Cheers,
    >
    > Dave.
    >




  3. #3
    Dave Dixson
    Guest

    Re: Returning newline from a function to a cell

    Thanks - it was the wrap text that was the problem. I did not realsie
    that when you press alt+return in the spreadsheet that it sets this
    automatically.

    Dave.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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