Working on a large macro to automate an end of day email process that involves sending emails to different customers. Everything is working fairly well except in the several instances that some firms have different emails for different employees. It would be simple if these employees were the only ones that would be sent to that email, but that is of course not the case.
I'm struggling to find a solution to finding the names and referencing the email. But referencing multiple names without knowing how many names it could be ahead of time (meaning in the future a firm could have 10 employees with the same email confirmation and some may have as little as 1 (for those that require separate emails per employee)). Would I use an array for this and test against the array? I would also need to store the employee names in order to ensure duplicates aren't created. See Text example and code below:
The names are stored in a sheet named emailMaster in this format say starting in cell(1,3) (Joe GoodGuy; James Johanson; Jimmy TheHat (All encapsulated in one cell)) and the email they correspond to is found at .Offset(0,1). To clarify, these gentlemen may work for the firm "CodersUnited", but their may be another group from the firm "CodersUnited", who require a different email address for their end of day receipts and they could be in cell(1,5) (Jimmy John; Franky TwoToes; Jimmy Hendrix) and their corresponding email found in .Offset(0,1).
Row ____________________C____________________ __D___ ___________________E____________________ __F__
1 Joe GoodGuy; James Johanson; Jimmy TheHat Emails Jimmy John; Frank TwoToes; Jimmy Hendrix Email
The solution below only works if their is one name corresponding to one email. There needs to be multiple names corresponding to one email.
'Gets firm name
If firmName = emailMaster.Cells(emrow_num, 1) Then
continue = False
cFirm = firmName
iFirm = emailMaster.Cells(emrow_num, 2)
If IsEmpty(emailMaster.Cells(emrow_num, 4)) = True Then
firmEmail = emailMaster.Cells(emrow_num, 3)
'Tests for separate employee emails
ElseIf emailMaster.Cells(emrow_num, 4) = "Yes" Then
empSeparate = True
'Captures separate emp email
Set empTestFinder = emailMaster.Rows(emrow_num).Find(empName)
empFinder = empTestFinder.Address
firmEmail = emailMaster.Range(empFinder).Offset(0, 1)
Else
MsgBox ("Firm designated as different emails for employees. Either change designation of firm or add employee. Contact dev for more assistance.")
Exit Sub
End If
End If