+ Reply to Thread
Results 1 to 6 of 6

I need to stop the loop to an empty cell on this email generating macro

  1. #1
    Registered User
    Join Date
    04-26-2014
    Location
    Metro Manila
    MS-Off Ver
    Excel 2007
    Posts
    2

    I need to stop the loop to an empty cell on this email generating macro

    Sub SendEmail(what_address As String, Subject_line As String, mail_body As String)

    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")

    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)

    olMail.To = what_address
    olMail.Subject = Subject_line
    olMail.Body = mail_body
    olMail.Save

    ___________________________________________


    End Sub
    Sub Massemail()

    row_number = 1
    Do
    DoEvents

    row_number = row_number + 1

    Dim mail_body_message As String
    Dim con_number As String
    Dim d_libres As String

    mail_body_message = Sheet1.Range("F2")
    con_number = Sheet1.Range("A" & row_number)
    d_libres = Sheet1.Range("B" & row_number)
    mail_body_message = Replace(mail_body_message, "cont_num", con_number)
    mail_body_message = Replace(mail_body_message, "d_l", d_libres)

    Call SendEmail(Sheet1.Range("D" & row_number), "LongStanding Test", mail_body_message)

    Loop Until row_number = 13

    End Sub







    In the line that says "Loop Until row_number = 13" I just put 13 to stop the generation of emails. Please advise anything that can resolve this or stop when it reaches an empty cell. Please see attachment for the screenshot of the excel file.


    Test Email1.jpg







    Thanks in advance

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: I need to stop the loop to an empty cell on this email generating macro

    Hi and welcome to the forum.
    Please use code tags around your code as per Forum rules.

    You can change your loop and stop it if a cell is empty :
    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    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,813

    Re: I need to stop the loop to an empty cell on this email generating macro

    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


  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,636

    Re: I need to stop the loop to an empty cell on this email generating macro

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  5. #5
    Registered User
    Join Date
    04-26-2014
    Location
    Metro Manila
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: I need to stop the loop to an empty cell on this email generating macro

    This is great man! Thanks for the help...

  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,813

    Re: I need to stop the loop to an empty cell on this email generating macro

    You're welcome.

    Please comply with the moderator's request and add code tags to your original post. Thanks.



    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. [SOLVED] If cell is empty in a variable range, stop macro and return error message
    By Andrei Kononenko in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-22-2019, 02:19 PM
  2. Replies: 3
    Last Post: 02-20-2014, 05:16 PM
  3. [SOLVED] getting MACRO to loop until cell is empty
    By El Conquistador in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2013, 08:58 AM
  4. [SOLVED] Macro skips generating last email
    By csit17 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-17-2012, 07:48 AM
  5. Macro to loop actions until empty cell
    By RobbieMoulton in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-29-2011, 02:59 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