+ Reply to Thread
Results 1 to 3 of 3

Sending Email - Loop Until last row (skipping blank cells)

  1. #1
    Registered User
    Join Date
    03-24-2015
    Location
    Ontario
    MS-Off Ver
    2010
    Posts
    2

    Sending Email - Loop Until last row (skipping blank cells)

    Hello,

    I am trying to setup an excel VBA (new to this) and I have it setup so that any email address in column B will receive a mass email from my work. The only problem is that the excel spreadsheet is shared so I have designated rows to each coworker which will end up leaving blank cells in column B. I currently have it setup so that if there are no blank cells it will loop until the last cell and send emails out to all email address in column B. But if there is a blank cell in column B in between the emails, it will not go to the next cell with an email address in it. Below is the VBA code for what I have. I wouldn't like to modify it too much, if someone could just help me on how to all emails in column b, skipping all blank cells!

    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.Send


    End Sub

    Sub SendMassEmail()


    row_number = 2

    Do
    DoEvents
    row_number = row_number + 1
    Dim mail_body_message As String
    Dim full_name As String
    mail_body_message = Sheet1.Range("H3")
    full_name = Sheet1.Range("C" & row_number) & " " & Sheet1.Range("D" & row_number)
    mail_body_message = Replace(mail_body_message, "replace_name_here", full_name)
    Call SendEmail(Sheet1.Range("B" & row_number), "This is a test email", mail_body_message)
    Loop Until row_number = Sheet1.Range("B99999").End(xlUp).Row


    MsgBox "Emails Sent"

    End Sub

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Sending Email - Loop Until last row (skipping blank cells)

    Please Login or Register  to view this content.
    And add a function (isEmail) to check if its a valid email
    Please Login or Register  to view this content.
    There are probably more comprehensive Functions for email checking available on google but that will do the basic check.
    Last edited by pjwhitfield; 03-27-2015 at 09:15 AM.
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    03-24-2015
    Location
    Ontario
    MS-Off Ver
    2010
    Posts
    2

    Re: Sending Email - Loop Until last row (skipping blank cells)

    Thank you so much! That worked, I really appreciate it.

+ 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. Skipping blank cells tp speed up a loop
    By jerrydiaz in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-14-2014, 07:58 PM
  2. [SOLVED] Skipping Blank Cells in a HTML Email Body
    By bocaj315 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2013, 04:03 PM
  3. Skipping blank cells in Email body
    By bocaj315 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-21-2013, 12:19 PM
  4. Replies: 0
    Last Post: 03-05-2013, 09:22 AM
  5. Use Vlookup to loop through and find each email address before sending
    By g1987 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2012, 03:04 PM

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