Email adresses from range simplified?

wigarth

Board Regular
Joined
Apr 16, 2016
Messages
51
Office Version
  1. 365
Platform
  1. Windows
Hi!

I have a code that generates and sends email using outlook.
the code that puts the adresses is something like this:

VBA Code:
'something code here
.to = Range("A1").value & ";" & Range("A2").value
'something more code here



the code is simple and working great so far...
The problem however, is that the range of adresses is so big, and alot of the cells containing adresses are even empty.

So, Is there a way to make vba make a list of reciepints from a range (C6:C776) an easier way?

Best reggards
Wigarth
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Maybe (untested)
VBA Code:
Sub test()
    Dim eVar() As Variant, x As Long, z As Long, rVar As Variant
   
    rVar = Range("C6:C776").Value
   
    For x = 1 To UBound(rVar)
        If rVar(x, 1) <> vbNullString Then
            ReDim Preserve eVar(z)
            eVar(z) = rVar(x, 1)
            z = z + 1
        End If
    Next x
   
    .to = Join(rVar, ";")
End Sub
 
Upvote 0
You should be able to loop through the range and add non-blank values to the list, something like this:
VBA Code:
    Dim cell As Range
    Dim emails As String
    
    For Each cell In Range("C6:C776")
        If cell.Value <> "" Then
            emails = emails & cell.Value & ";"
        End If
    Next cell
    
    MsgBox emails
 
Upvote 0
Solution
You should be able to loop through the range and add non-blank values to the list, something like this:
VBA Code:
    Dim cell As Range
    Dim emails As String
   
    For Each cell In Range("C6:C776")
        If cell.Value <> "" Then
            emails = emails & cell.Value & ";"
        End If
    Next cell
   
    MsgBox emails
Worked perfectly. Many thanks to you kind Joe4. Wishing you a happy easter.
 
Upvote 0

Forum statistics

Threads
1,215,139
Messages
6,123,263
Members
449,093
Latest member
Vincent Khandagale

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