TheWennerWoman
Active Member
- Joined
- Aug 1, 2019
- Messages
- 308
- Office Version
- 365
- Platform
- Windows
I am using a function to validate email addresses on a sheet. Most of the time there is just the one email address in a cell but there are occasions when there are two separated by a semi-colon
So before passing the email addresses to the function, I am splitting like this
However, I am getting a "subscript out of range" error on the variable secondemail whenever there's just a single email address (I assume because result2(1) doesn't exist in those cases).
I can fudge my way through with an On Error Resume Next but I don't like doing that because it'a apparently bad practice
Is there another way I can try?
Thank you for reading.
Code:
donald.duck@disneyworld.com; mickey.mouse@disneyworld.com
So before passing the email addresses to the function, I am splitting like this
VBA Code:
For a = 2 To lrow2
'On Error Resume Next
emailtoparse = Sheet6.Range("B" & a).Value
result2 = Split(emailtoparse, ";")
firstemail = result2(0)
secondemail = LTrim(result2(1))
However, I am getting a "subscript out of range" error on the variable secondemail whenever there's just a single email address (I assume because result2(1) doesn't exist in those cases).
I can fudge my way through with an On Error Resume Next but I don't like doing that because it'a apparently bad practice
Is there another way I can try?
Thank you for reading.