+ Reply to Thread
Results 1 to 15 of 15

Formatting a string in a message box?

  1. #1
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Formatting a string in a message box?

    Hello,

    A specific cell contains the following text:

    "Status bit name: TIMER STATE Status bit# : 0: Value :0: Timer off Value :1: Timer on"

    However, later I want to display it in a message box like this:

    ----------------------------------------------
    Status bit name: TIMER STATE
    Status bit# : 0:

    Value :0: Timer off
    Value :1: Timer on
    ----------------------------------------------

    So I tried to store the string in the cell like this:

    "Status bit name: TIMER STATE & vbNewline & Status bit# : 0: & vbNewine & Value :0: Timer off & vbNewline & Value :1: Timer on"

    and call it like this:

    Please Login or Register  to view this content.
    But it displays like this:

    Status bit name: TIMER STATE & vbNewline & Status bit# : 0: & vbNewine & Value :0: Timer off & vbNewline & Value :1: Timer on


    Honestly, that's what I pretty much expected but it was worth a try

    So is there an easy way to take the textual contents of a cell and format the text so that it appears in a message box as I explained above?

    Thanks all for your help!
    Rn

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Formatting a string in a message box?

    Where are the valued for TIMER STATE, Status bit# etc coming from?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274
    Quote Originally Posted by Norie View Post
    Where are the valued for TIMER STATE, Status bit# etc coming from?
    Well,at this point, this text is used for information only..... thus
    informing the user that the timer had two status bits
    which denotes as the timer being on or off.

    So I just need to take the text and display it
    as explained in the initial post....

    thanks for replying

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Formatting a string in a message box?

    If you have 'Status bit name: TIMER STATE Status bit# : 0: Value :0: Timer off Value :1: Timer on' hard coded in the cell then I'm afraid I can't see how you can display it with line breaks in the message box.

    Have you tried manually adding line breaks in the cell using ALT+ENTER?

  5. #5
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Re: Formatting a string in a message box?

    Yes, if I enter the text manually in a cell and use "ALT"/"ENTER" every time I want to feed a new line, then this works.

    However, different information is stored in that cell and therefore, VBA code has to do the initial storing to the cell.

    In reality, in dependence of several factors, cell "1,16" or (1P) gets its contents like this:

    Please Login or Register  to view this content.
    then later, I need to display them in a message box like this:


    ----------------------------------------------
    Status bit name: TIMER STATE
    Status bit# : 0:

    Value :0: Timer off
    Value :1: Timer on
    ----------------------------------------------

    By using the following code:

    Please Login or Register  to view this content.
    I thought perhaps that Excel would have some special characters we can introduce in the string upon creation so
    that the message box would then interpret these as textual placement operations such as, tabbing, newline etc...

    I was wondering is there a textual character that I can insert in the string that would correspond to "ALT"/ENTER"
    which could instruct the message box to carry out a line feed?

    OR ELSE.....

    I may just have to get into complicated string manipulations ... which I really don't feel like it

    Let me know what one really should do in a situation like this!!

    Thanks for replying
    Rn
    Last edited by RustyNail; 05-18-2015 at 02:38 PM.

  6. #6
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Re: Formatting a string in a message box?

    Bof .... this seems to work!!!!!

    Cells(1, 16).Value = "Status bit #0:" & vbNewLine & "TMR ON FLAG:" & vbNewLine & "Value :0: Timer off " & vbNewLine & " Value :1: Timer on"

    Go figure....

    Rn

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Formatting a string in a message box?

    If you had some sort of pattern or a delimiter in the string then you could possible do something but as far as I can see you don't.

  8. #8
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    Re: Formatting a string in a message box?

    Ha ha!

    This didn't work after all because it heightens my cell by a lot ... don't know why but it does!!!!

    "If you had some sort of pattern or a delimiter in the string then you could possible do something but as far as I can see you don't"

    What do you mean ? Maybe I can

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Formatting a string in a message box?

    By a delimiter I mean a character that can be used to determine how to separate the long string into separate lines.

    When I first looked at your post I thought that ':' might have been a candidate for that but unfortunately that won't work.

  10. #10
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274
    Quote Originally Posted by Norie View Post
    By a delimiter I mean a character that can be used to determine how to separate the long string into separate lines.

    When I first looked at your post I thought that ':' might have been a candidate for that but unfortunately that won't work.
    Well, to be honest.... everything is manageable !
    I can pick a character that I feel can be used as a delimiter....

    How about the "|" character?

    So what can we do now that we agreed on a delimited character?

    thanks Norie!

  11. #11
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274
    Quote Originally Posted by Norie View Post
    By a delimiter I mean a character that can be used to determine how to separate the long string into separate lines.

    When I first looked at your post I thought that ':' might have been a candidate for that but unfortunately that won't work.
    Well, to be honest.... everything is manageable !
    I can pick a character that I feel can be used as a delimiter....

    How about the "|" character?

    So what can we do now that we agreed on a delimited character?

    thanks Norie!

  12. #12
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Formatting a string in a message box?

    Perhaps Norie was thinking of something like this.
    Attached Files Attached Files
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Formatting a string in a message box?

    I was actually thinking more along these lines.
    Please Login or Register  to view this content.

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

    Re: Formatting a string in a message box?

    deleted.....
    Last edited by protonLeah; 05-18-2015 at 09:42 PM.
    Ben Van Johnson

  15. #15
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Formatting a string in a message box?

    Quote Originally Posted by Norie View Post
    I was actually thinking more along these lines.
    Please Login or Register  to view this content.
    I like that. Into the toolbox it goes.

+ 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. Formatting a Message Box
    By M4RSH in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2013, 09:29 AM
  2. Replies: 1
    Last Post: 08-28-2013, 09:07 AM
  3. Adding formatting to a message box
    By dextras in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2009, 03:02 AM
  4. Formatting a variable used in a message
    By akronpow in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2007, 05:53 PM
  5. Formatting Message Boxes
    By ChemistB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2007, 05:48 AM

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