+ Reply to Thread
Results 1 to 25 of 25

Adding carriage return

  1. #1
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Adding carriage return

    The following is partially made from code that I did not create so I can't claim to fully understand it. What it needs to do is take A1:B21 and email it out. However above the info from A1:B21, I would like to add data from another sheet (called Outages).

    I can get it to do what I want except that instead of taking Outages!A2, A3, A4, etc and adding a carriage return, it runs it all together like one big paragraph. I am sure it's as simple as adding the right bit of code but I can't seem to put it in the right spot.

    The current macro is
    Please Login or Register  to view this content.
    Any assistance would be appreciated

  2. #2
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: Adding carriage return

    Hi Wheelie,

    The command "vbNewLine" should add a carriage return to the body of your text. The line in your code that reads:

    Please Login or Register  to view this content.
    is an example of the "vbNewLine" command being used in a message box to provide a return in the message.

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

    Re: Adding carriage return

    There doesn't seem to be anything in that code that does anything with 'Outages'.
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: Adding carriage return

    ...to add to my earlier post, I did notice that the commands "vbCrLf" and "vbNewLine" don't work with the ".HTMLBody" variable, they work with the ".Body" variable. If you want a good example, Ron DeBruin has one here where he adds carriage returns to an e-mail message.

    http://www.rondebruin.nl/win/s1/outlook/bmail4.htm

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Adding carriage return

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Adding carriage return

    I note that you have been on the board several times since a solution was provided.

    I am interested to know if it resolved your problem.

    Regards, TMS

  7. #7
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Adding carriage return

    TMShucks - Your code provided me with the solution but now the info from A1:B21 is missing

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Adding carriage return

    Probably just misunderstood the requirement. Always best to provide a sample workbook.

    I removed the select and then qualified the range. Now it has two ranges.

    Please Login or Register  to view this content.

    Regards, TMS

  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: Adding carriage return

    Wheelie

    Which range do you want from Outages?

  10. #10
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Adding carriage return

    Norie
    Worksheet name is Outages
    Range is A2 to indefinite. I never know how many rows of data could be there. It could be 0 or it could be 100 or more

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

    Re: Adding carriage return

    Wheelie

    But is it only column A from Outages?

  12. #12
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Adding carriage return

    TMShucks - Sorry if the info I gave didn't give enough info to go on. In the future I'll give a bit of the workbook if I can.
    With a bit of finetunning of where I want things placed, your new code did the trick. The only problem I foree is that the following line will only allow me to go down to B21. I could have alot of info then 21 rows. It could be 0 or it could be 100 or more.
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Adding carriage return

    Yes Norie Only 1 column but it could be multiple rows down

  14. #14
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Adding carriage return

    try this
    Please Login or Register  to view this content.
    Last edited by john55; 01-02-2014 at 01:24 PM. Reason: "a1:b...
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  15. #15
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Adding carriage return

    john55 - rng and rngO repeated themselves so I just used the following

    Please Login or Register  to view this content.
    The problem now lies with rng only giving me 19 rows of data even if I have more on my Outages sheet.

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

    Re: Adding carriage return

    Wheelie

    Do you want columns A and B from Outages, or just column A?

    Columns A & B.
    Please Login or Register  to view this content.
    Column A.
    Please Login or Register  to view this content.

  17. #17
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Adding carriage return

    I just tested and it gives me the correct number of rws, see wkb attached
    Attached Files Attached Files

  18. #18
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Adding carriage return

    As far as I am aware, the OP has not provided sufficient information for a definitive solution to be given.

    I started with the assumption that the data required was in the Outages worksheet ... a fixed range. Then, when an issue was identified, I repeated the original range and duplicated it on the Outages sheet.

    If the number of rows on either of the sheets varies, it should only be a matter of establishing the last row on each of the sheets.

    I think it is down to the OP to provide the data so that we don't spend time stabbing in the dark.


    Regards, TMS

  19. #19
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Adding carriage return

    TMShucks
    Part 1 of my email is from my Outages worksheet which is not a fixed range. The entire sheet could be blank or it could be A2 to A infinity. The # of rows would never decrease but could potentially increase.
    Part 2 of my email is a fixed range of A1:B21 on a sheet called NBReport Outage Client E-Mail

  20. #20
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Adding carriage return

    john55 - I'm at a loss to explain why yours works and mine doesn't. The only difference should be my sheet is called Outages and yours is called Sheet1...

  21. #21
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Adding carriage return

    if you make a copy of yr file without sensitive data and upload it here perhaps someone can see the issue...

  22. #22
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Adding carriage return

    Thanks everyone for your help, I've been away for a few weeks unexpectedly. The code I have now is as follows and the only issue I am having now is instead of taking everything from A1 down on the Outages page, it's taking only the last populated row.

    Please Login or Register  to view this content.
    Does anyone have any insight? The specific line that I think is causing the issue is as follows
    Please Login or Register  to view this content.

  23. #23
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Adding carriage return

    Please Login or Register  to view this content.

    Regards, TMS

  24. #24
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Adding carriage return

    Please Login or Register  to view this content.

    Regards, TMS

  25. #25
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Adding carriage return

    Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Carriage Return
    By hezcal1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2012, 09:27 AM
  2. Tab Carriage Return
    By WhtKnt in forum Excel General
    Replies: 5
    Last Post: 01-05-2011, 05:00 PM
  3. [SOLVED] Carriage Return in a Concatenation
    By [email protected] in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 08-12-2006, 12:15 PM
  4. Carriage Return
    By rexmann in forum Excel General
    Replies: 3
    Last Post: 05-09-2006, 11:25 AM
  5. Strip carriage return, add row
    By adin in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 04-26-2005, 05:06 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