Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
445
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi All,

I am having an issue in Excel. My current setup looks like this:

1642673709403.png


However, if I put range("O2") it works fine and it sends out the email to my email address. But once I try to increase the range and make it send out to multiple emails, it comes with the following error (highlighting the line above):

1642673695774.png


Does anybody know how to fix this issue? It would truly help!!

Thank you :)

Kind regards,
Jyggalag
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You can't pass an array to the To property, it needs a delimited string. You can use a function like:

Code:
Function GetAddressesFromRange(InputRange As Range, Optional Delimiter As String = ";") As String
    Dim Cell As Range
    For Each Cell In InputRange.Cells
        Dim EmailList As String
        If Len(Cell.Value) <> 0 Then
            EmailList = EmailList & Delimiter & Cell.Value
        End If
    Next Cell
    If Len(EmailList) <> 0 Then GetAddressesFromRange = Mid$(EmailList, Len(Delimiter) + 1)
End Function

then in your calling code use:

Code:
.To = GetAddressesFromRange(Range("O2:O10"))

Side note, posting your code as pictures really doesn't help us to help you. ;)
 
Upvote 0
Solution
Hi
what about
VBA Code:
EmailItem.to = Join(Filter(Application.Transpose(Range("O2:O10")), " ", False), ";")
 
Upvote 0
You can't pass an array to the To property, it needs a delimited string. You can use a function like:

Code:
Function GetAddressesFromRange(InputRange As Range, Optional Delimiter As String = ";") As String
    Dim Cell As Range
    For Each Cell In InputRange.Cells
        Dim EmailList As String
        If Len(Cell.Value) <> 0 Then
            EmailList = EmailList & Delimiter & Cell.Value
        End If
    Next Cell
    If Len(EmailList) <> 0 Then GetAddressesFromRange = Mid$(EmailList, Len(Delimiter) + 1)
End Function

then in your calling code use:

Code:
.To = GetAddressesFromRange(Range("O2:O10"))

Side note, posting your code as pictures really doesn't help us to help you. ;)
@mohadin and @RoryA Amazing!!

I tested both of your solutions and they both work!! Mohadins seems more simple, but maybe i'm missing an advantage from yours Rory?

Nonetheless thank you so much!! I wish I could mark 2 solutions haha

Update: Will make sure to post code in the future! :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,150
Members
452,615
Latest member
bogeys2birdies

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