How do you do you remove empty values in a column in excel VBA?

  Kiến thức lập trình

So I have a table with emails and the contact person. Not all contact persons have Email. I want to filter out the empty email column values.

Email Contact Person
[email protected] Jesse
Meowth
[email protected] James

here is my VBA code

Sub SendMultipleEmails() 

Dim OutApp As New Outlook.Application 

Dim OutMail As MailItem 

lr = Cells(Rows.Count, "B").End(xlUp).Row 
' Since B is the second row and this list is complete
msg_1 = "To PRotect the world from devastation?" & vbLf & vbLf 


For r = 2 To lr 'To ignore the header

    If Range("A" & r).Value <> "" then Set OutMail = OutApp.CreateItem(olMailItem) 

     

    With OutMail 

        .To = Range("A" & r).Value 

        .Subject = "Team Rocket Chant" 

        .Body = msg_1

             

        .CC = Range("C" & r).Value 

        .Display

    End With 

Next r 

 

Set OutMail = Nothing 

Set OutApp = Nothing 
End Sub 

     

However I still get a display of the email with an empty email string in outlook before I can send. I just want to send the the emails with Only email.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT