+ Reply to Thread
Results 1 to 6 of 6

Select All Populated Cells for StrBody

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

    Select All Populated Cells for StrBody

    I have the following code that attaches a workbook with Sheet(1).Range("E1:N9") in the body of the email. However I'd like to add column A of the 2nd sheet as regular text after my RangeToHTML. I thought strBody would be the solution, however it's only adding the last populated row in column A instead of ALL populated rows. Column A would have a minimum of 1 row(s) but could have many more after. I'm sure it's just a typo that I can't think of how to fix.

    Ideas?

    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Select All Populated Cells for StrBody

    StrBody is explicitly getting the last row of data in A. You need to set up a loop to build up StrBody, maybe something like this:

    Please Login or Register  to view this content.
    I don't know how you want it formatted, though.

  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: Select All Populated Cells for StrBody

    All this is going to return is the last value in column A on the 2nd sheet.
    Please Login or Register  to view this content.
    If you wanted to handle an entire row you would first need to return that row in the code and then process that row to produce valid HTML.

    Even then it might not be enough to simply tack that on at the end of the HTML returned by RangeToHTML.

    What I would suggest is copy E1:N9 from the first sheet to a blank sheet, copying the last row from the second sheet below that and then passing that range to RangeToHTML.
    If posting code please use code tags, see here.

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

    Re: Select All Populated Cells for StrBody

    Thanks 6StringJazzer! That works however I'd like it to put a carriage return between each cell contents. Right now it just comes out as a run-on sentence.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Select All Populated Cells for StrBody

    You said "regular text" so I wasn't sure what you wanted. Since you are using HTML format try this:
    Please Login or Register  to view this content.

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

    Re: Select All Populated Cells for StrBody

    That's perfect! Thanks very much.

+ 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] VBA for Strbody
    By kieranm105 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-24-2018, 04:20 AM
  2. [SOLVED] Select populated data
    By Brett854 in forum Excel General
    Replies: 8
    Last Post: 05-18-2017, 05:45 AM
  3. [SOLVED] Add hyperlink to text in strbody
    By Rosco88 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-06-2017, 05:31 AM
  4. Excel Cells populated by select count(*)
    By fralo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-12-2014, 09:39 AM
  5. [SOLVED] vbnewline at strbody is not working. Please help
    By alexnkc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-18-2013, 02:14 AM
  6. Replies: 1
    Last Post: 09-27-2012, 10:42 AM
  7. Select all populated cells
    By Cram in forum Excel General
    Replies: 2
    Last Post: 03-31-2008, 09:43 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