How to take care of empty cells in Excell

navimir

New Member
Joined
May 6, 2013
Messages
1
Hello,
I want to send email to list of users which are stored in Excel from A1 to A10.
But if suppose if any of the cells from A1 to A10 is empty then it gives error..
how to take care of empty cells??

Function SendMail()
Dim y As String
y = Sheets(1).Range("A1:A10").Value
' Copy the sheet(1)
ThisWorkbook.Sheets(1).Copy
' Send Email
With ActiveWorkbook
.SendMail Recipients:=y, Subject:="test" & Format(Date, "dd/mmm/yy")
.Close SaveChanges:=False
End With
End Function
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Isn't better for you if you assign the values of A1:A10 to "y" separating them with ";"....
i.e:Someone;SomoneElse;;;.. without having spaces.
Code:
Function SendMail()
Dim y As String
Rem Set recipients to y seperated by ;
For Each Cell In Range("A1:A10")
    If IsEmpty(Cell) = False Then
       If y = "" Then
          y = Cell.Value
       Else
          y = y & ";" & Cell.Value
       End If
    End If
Next
' Copy the sheet(1)
ThisWorkbook.Sheets(1).Copy
' Send Email
With ActiveWorkbook
.SendMail Recipients:=y, Subject:="test" & Format(Date, "dd/mmm/yy")
.Close SaveChanges:=False
End With
End Function
ZAX
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,121
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top