Send email to multiple people based on common cell value using Excel VBA












0














I would like to add multiple recipients and attachments to one email message dictated by the value in a column.



I need to have people update their resumes, which will be attached, but I would like to group the emails by manager. The # of people under each manager ranges from 1-14.



The columns I have are:

B: Mgr Email address

C: Mgr last name

D: Employee email

E: Emp first name

F: Emp last name

G: Status of resume



I created a macro that will loop through and create an email with proper attachment for each entry.



I'd like to switch this to groups of employees by the value in column C or B. I have an inkling this will include arrays. I am a VBA novice.



What I have so far (with specific paths/emails renamed for privacy):



Sub Test2()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim sSourcePath As String
Dim flpath As String
flpath = "C:Resumes"

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")

On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'XYZ email address was hardcoded for testing purposes, but should also loop
If cell.Value = "XYZ@gmail.com" And _
Cells(cell.Row, "G").Value = "4. Need Update" _
Then

Set OutMail = OutApp.CreateItem(0)
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")

On Error Resume Next
With OutMail
.To = cell.Value & ", " & Cells(cell.Row, "D").Value
'cced address is static
.CC = "ZZZ@gmail.com"
.Subject = "Resume needed"
.body = "Howdy!" _
& vbNewLine & vbNewLine & _
"Body text"

.attachments.Add flpath & sSourcePath
.Display 'Or use Display

End With
On Error GoTo 0
Set OutMail = Nothing
End If

Next cell

cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub









share|improve this question
























  • You want to send one e-mail to the manager of everyone who needs to update his résumé? You want to send one e-mail and cc: everyone who has the same manager, attaching all résumés? I'm not sure what you mean by "I'd like to switch this to groups of employees by the value in column C or B." Also, how will you choose which column to use? Like, if last name is blank, use e-mail? But that might create multiple groups for the same manager. etc. Seems like some detail is missing.
    – StoneGiant
    Nov 12 '18 at 16:23










  • Are you allowed to sort the sheet by column B or C?
    – StoneGiant
    Nov 12 '18 at 16:25
















0














I would like to add multiple recipients and attachments to one email message dictated by the value in a column.



I need to have people update their resumes, which will be attached, but I would like to group the emails by manager. The # of people under each manager ranges from 1-14.



The columns I have are:

B: Mgr Email address

C: Mgr last name

D: Employee email

E: Emp first name

F: Emp last name

G: Status of resume



I created a macro that will loop through and create an email with proper attachment for each entry.



I'd like to switch this to groups of employees by the value in column C or B. I have an inkling this will include arrays. I am a VBA novice.



What I have so far (with specific paths/emails renamed for privacy):



Sub Test2()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim sSourcePath As String
Dim flpath As String
flpath = "C:Resumes"

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")

On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'XYZ email address was hardcoded for testing purposes, but should also loop
If cell.Value = "XYZ@gmail.com" And _
Cells(cell.Row, "G").Value = "4. Need Update" _
Then

Set OutMail = OutApp.CreateItem(0)
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")

On Error Resume Next
With OutMail
.To = cell.Value & ", " & Cells(cell.Row, "D").Value
'cced address is static
.CC = "ZZZ@gmail.com"
.Subject = "Resume needed"
.body = "Howdy!" _
& vbNewLine & vbNewLine & _
"Body text"

.attachments.Add flpath & sSourcePath
.Display 'Or use Display

End With
On Error GoTo 0
Set OutMail = Nothing
End If

Next cell

cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub









share|improve this question
























  • You want to send one e-mail to the manager of everyone who needs to update his résumé? You want to send one e-mail and cc: everyone who has the same manager, attaching all résumés? I'm not sure what you mean by "I'd like to switch this to groups of employees by the value in column C or B." Also, how will you choose which column to use? Like, if last name is blank, use e-mail? But that might create multiple groups for the same manager. etc. Seems like some detail is missing.
    – StoneGiant
    Nov 12 '18 at 16:23










  • Are you allowed to sort the sheet by column B or C?
    – StoneGiant
    Nov 12 '18 at 16:25














0












0








0







I would like to add multiple recipients and attachments to one email message dictated by the value in a column.



I need to have people update their resumes, which will be attached, but I would like to group the emails by manager. The # of people under each manager ranges from 1-14.



The columns I have are:

B: Mgr Email address

C: Mgr last name

D: Employee email

E: Emp first name

F: Emp last name

G: Status of resume



I created a macro that will loop through and create an email with proper attachment for each entry.



I'd like to switch this to groups of employees by the value in column C or B. I have an inkling this will include arrays. I am a VBA novice.



What I have so far (with specific paths/emails renamed for privacy):



Sub Test2()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim sSourcePath As String
Dim flpath As String
flpath = "C:Resumes"

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")

On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'XYZ email address was hardcoded for testing purposes, but should also loop
If cell.Value = "XYZ@gmail.com" And _
Cells(cell.Row, "G").Value = "4. Need Update" _
Then

Set OutMail = OutApp.CreateItem(0)
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")

On Error Resume Next
With OutMail
.To = cell.Value & ", " & Cells(cell.Row, "D").Value
'cced address is static
.CC = "ZZZ@gmail.com"
.Subject = "Resume needed"
.body = "Howdy!" _
& vbNewLine & vbNewLine & _
"Body text"

.attachments.Add flpath & sSourcePath
.Display 'Or use Display

End With
On Error GoTo 0
Set OutMail = Nothing
End If

Next cell

cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub









share|improve this question















I would like to add multiple recipients and attachments to one email message dictated by the value in a column.



I need to have people update their resumes, which will be attached, but I would like to group the emails by manager. The # of people under each manager ranges from 1-14.



The columns I have are:

B: Mgr Email address

C: Mgr last name

D: Employee email

E: Emp first name

F: Emp last name

G: Status of resume



I created a macro that will loop through and create an email with proper attachment for each entry.



I'd like to switch this to groups of employees by the value in column C or B. I have an inkling this will include arrays. I am a VBA novice.



What I have so far (with specific paths/emails renamed for privacy):



Sub Test2()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim sSourcePath As String
Dim flpath As String
flpath = "C:Resumes"

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")

On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'XYZ email address was hardcoded for testing purposes, but should also loop
If cell.Value = "XYZ@gmail.com" And _
Cells(cell.Row, "G").Value = "4. Need Update" _
Then

Set OutMail = OutApp.CreateItem(0)
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")

On Error Resume Next
With OutMail
.To = cell.Value & ", " & Cells(cell.Row, "D").Value
'cced address is static
.CC = "ZZZ@gmail.com"
.Subject = "Resume needed"
.body = "Howdy!" _
& vbNewLine & vbNewLine & _
"Body text"

.attachments.Add flpath & sSourcePath
.Display 'Or use Display

End With
On Error GoTo 0
Set OutMail = Nothing
End If

Next cell

cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub






excel vba outlook outlook-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 1:22









Community

11




11










asked Nov 12 '18 at 15:56









LBJ

63




63












  • You want to send one e-mail to the manager of everyone who needs to update his résumé? You want to send one e-mail and cc: everyone who has the same manager, attaching all résumés? I'm not sure what you mean by "I'd like to switch this to groups of employees by the value in column C or B." Also, how will you choose which column to use? Like, if last name is blank, use e-mail? But that might create multiple groups for the same manager. etc. Seems like some detail is missing.
    – StoneGiant
    Nov 12 '18 at 16:23










  • Are you allowed to sort the sheet by column B or C?
    – StoneGiant
    Nov 12 '18 at 16:25


















  • You want to send one e-mail to the manager of everyone who needs to update his résumé? You want to send one e-mail and cc: everyone who has the same manager, attaching all résumés? I'm not sure what you mean by "I'd like to switch this to groups of employees by the value in column C or B." Also, how will you choose which column to use? Like, if last name is blank, use e-mail? But that might create multiple groups for the same manager. etc. Seems like some detail is missing.
    – StoneGiant
    Nov 12 '18 at 16:23










  • Are you allowed to sort the sheet by column B or C?
    – StoneGiant
    Nov 12 '18 at 16:25
















You want to send one e-mail to the manager of everyone who needs to update his résumé? You want to send one e-mail and cc: everyone who has the same manager, attaching all résumés? I'm not sure what you mean by "I'd like to switch this to groups of employees by the value in column C or B." Also, how will you choose which column to use? Like, if last name is blank, use e-mail? But that might create multiple groups for the same manager. etc. Seems like some detail is missing.
– StoneGiant
Nov 12 '18 at 16:23




You want to send one e-mail to the manager of everyone who needs to update his résumé? You want to send one e-mail and cc: everyone who has the same manager, attaching all résumés? I'm not sure what you mean by "I'd like to switch this to groups of employees by the value in column C or B." Also, how will you choose which column to use? Like, if last name is blank, use e-mail? But that might create multiple groups for the same manager. etc. Seems like some detail is missing.
– StoneGiant
Nov 12 '18 at 16:23












Are you allowed to sort the sheet by column B or C?
– StoneGiant
Nov 12 '18 at 16:25




Are you allowed to sort the sheet by column B or C?
– StoneGiant
Nov 12 '18 at 16:25












1 Answer
1






active

oldest

votes


















0














If I'm guessing correctly at what you want, here's a way that uses a collection of e-mails by manager. They are created as you go, and then when you're finished, you can do whatever you want to the messages in the collection.



Dim allMessages as Collection
Dim currMessage as Object
Set allMessages = New Collection

For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If Cells(cell.Row, "G").Value = "4. Need Update"
' Find the e-mail for the present manager
For Each currMessage in allMessages
If currMessage.CC = cell.Value Then
Exit For
End If
Next currMessage

' Create it, if it wasn't found
If currMessage Is Nothing Then
Set currMessage = OutApp.CreateItem(0)
allMessages.Add currMessage
With currMessage
.CC = cell.Value
.Subject = "Résumé Needed"
.Body = "Howdy!" & vbNewLine & vbNewLine & "Body text."
End With
End If

' Add the Message Recipient and Attachment
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")
With currMessage
.To = .To & Iif(Len(.To) > 0,";","") & _
cell.Value & ", " & Cells(cell.Row, "D").Value
.Attachments.Add flpath & sSourcePath
End With

Set currMessage = Nothing

End If
Next cell

' Now do something with the messages.
For Each currMessage In allMessages
currMessage.Display
End If

Set currMessage = Nothing
Set allMessages = Nothing


Caveat: Given that I don't have your data and don't use Outlook presently, I have not tested the above code snippet. The snippet primarily replaces your For...NextLoop, with an additional loop and clean up at the end, some declarations at the beginning. Let me know if it gives you problems, and I'll try to fix this answer based on what you tell me.






share|improve this answer























  • Thank you! I'll give this a test. To answer your previous questions, I can certainly sort the sheet. Also, I am hoping to send one e-mail and cc: everyone who has the same manager, attaching all résumés. I just meant Col C or B, doesn't matter which to choose. C is likely better anyways. Thanks again, I'll see how this works!
    – LBJ
    Nov 12 '18 at 17:08










  • If you sort the sheet, you don't need the collection. You can sort by the column you want, and walk down through the list building your message. When the manager name changes, send the one you've built and start a new one. The code currently provided doesn't require the sheet to be sorted.
    – StoneGiant
    Nov 12 '18 at 17:21










  • The code is having compiling errors - it doesn't understand where the bottom End If in the first chunk is coming from: If Cells(cell.Row, "G").Value = "4. Need Update" ' Find the e-mail for the present manager For Each currMessage in allMessages If currMessage.CC = cell.Value Then Exit For End If End If It also doesn't understand the Next cell or End If right above the Next cell. Any insight?
    – LBJ
    Nov 12 '18 at 20:48












  • I put an End If at the end of the For loop instead of a Next. Sorry. I'll fix it.
    – StoneGiant
    Nov 13 '18 at 16:55










  • It should be all set now.
    – StoneGiant
    Nov 13 '18 at 17:01











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265774%2fsend-email-to-multiple-people-based-on-common-cell-value-using-excel-vba%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If I'm guessing correctly at what you want, here's a way that uses a collection of e-mails by manager. They are created as you go, and then when you're finished, you can do whatever you want to the messages in the collection.



Dim allMessages as Collection
Dim currMessage as Object
Set allMessages = New Collection

For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If Cells(cell.Row, "G").Value = "4. Need Update"
' Find the e-mail for the present manager
For Each currMessage in allMessages
If currMessage.CC = cell.Value Then
Exit For
End If
Next currMessage

' Create it, if it wasn't found
If currMessage Is Nothing Then
Set currMessage = OutApp.CreateItem(0)
allMessages.Add currMessage
With currMessage
.CC = cell.Value
.Subject = "Résumé Needed"
.Body = "Howdy!" & vbNewLine & vbNewLine & "Body text."
End With
End If

' Add the Message Recipient and Attachment
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")
With currMessage
.To = .To & Iif(Len(.To) > 0,";","") & _
cell.Value & ", " & Cells(cell.Row, "D").Value
.Attachments.Add flpath & sSourcePath
End With

Set currMessage = Nothing

End If
Next cell

' Now do something with the messages.
For Each currMessage In allMessages
currMessage.Display
End If

Set currMessage = Nothing
Set allMessages = Nothing


Caveat: Given that I don't have your data and don't use Outlook presently, I have not tested the above code snippet. The snippet primarily replaces your For...NextLoop, with an additional loop and clean up at the end, some declarations at the beginning. Let me know if it gives you problems, and I'll try to fix this answer based on what you tell me.






share|improve this answer























  • Thank you! I'll give this a test. To answer your previous questions, I can certainly sort the sheet. Also, I am hoping to send one e-mail and cc: everyone who has the same manager, attaching all résumés. I just meant Col C or B, doesn't matter which to choose. C is likely better anyways. Thanks again, I'll see how this works!
    – LBJ
    Nov 12 '18 at 17:08










  • If you sort the sheet, you don't need the collection. You can sort by the column you want, and walk down through the list building your message. When the manager name changes, send the one you've built and start a new one. The code currently provided doesn't require the sheet to be sorted.
    – StoneGiant
    Nov 12 '18 at 17:21










  • The code is having compiling errors - it doesn't understand where the bottom End If in the first chunk is coming from: If Cells(cell.Row, "G").Value = "4. Need Update" ' Find the e-mail for the present manager For Each currMessage in allMessages If currMessage.CC = cell.Value Then Exit For End If End If It also doesn't understand the Next cell or End If right above the Next cell. Any insight?
    – LBJ
    Nov 12 '18 at 20:48












  • I put an End If at the end of the For loop instead of a Next. Sorry. I'll fix it.
    – StoneGiant
    Nov 13 '18 at 16:55










  • It should be all set now.
    – StoneGiant
    Nov 13 '18 at 17:01
















0














If I'm guessing correctly at what you want, here's a way that uses a collection of e-mails by manager. They are created as you go, and then when you're finished, you can do whatever you want to the messages in the collection.



Dim allMessages as Collection
Dim currMessage as Object
Set allMessages = New Collection

For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If Cells(cell.Row, "G").Value = "4. Need Update"
' Find the e-mail for the present manager
For Each currMessage in allMessages
If currMessage.CC = cell.Value Then
Exit For
End If
Next currMessage

' Create it, if it wasn't found
If currMessage Is Nothing Then
Set currMessage = OutApp.CreateItem(0)
allMessages.Add currMessage
With currMessage
.CC = cell.Value
.Subject = "Résumé Needed"
.Body = "Howdy!" & vbNewLine & vbNewLine & "Body text."
End With
End If

' Add the Message Recipient and Attachment
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")
With currMessage
.To = .To & Iif(Len(.To) > 0,";","") & _
cell.Value & ", " & Cells(cell.Row, "D").Value
.Attachments.Add flpath & sSourcePath
End With

Set currMessage = Nothing

End If
Next cell

' Now do something with the messages.
For Each currMessage In allMessages
currMessage.Display
End If

Set currMessage = Nothing
Set allMessages = Nothing


Caveat: Given that I don't have your data and don't use Outlook presently, I have not tested the above code snippet. The snippet primarily replaces your For...NextLoop, with an additional loop and clean up at the end, some declarations at the beginning. Let me know if it gives you problems, and I'll try to fix this answer based on what you tell me.






share|improve this answer























  • Thank you! I'll give this a test. To answer your previous questions, I can certainly sort the sheet. Also, I am hoping to send one e-mail and cc: everyone who has the same manager, attaching all résumés. I just meant Col C or B, doesn't matter which to choose. C is likely better anyways. Thanks again, I'll see how this works!
    – LBJ
    Nov 12 '18 at 17:08










  • If you sort the sheet, you don't need the collection. You can sort by the column you want, and walk down through the list building your message. When the manager name changes, send the one you've built and start a new one. The code currently provided doesn't require the sheet to be sorted.
    – StoneGiant
    Nov 12 '18 at 17:21










  • The code is having compiling errors - it doesn't understand where the bottom End If in the first chunk is coming from: If Cells(cell.Row, "G").Value = "4. Need Update" ' Find the e-mail for the present manager For Each currMessage in allMessages If currMessage.CC = cell.Value Then Exit For End If End If It also doesn't understand the Next cell or End If right above the Next cell. Any insight?
    – LBJ
    Nov 12 '18 at 20:48












  • I put an End If at the end of the For loop instead of a Next. Sorry. I'll fix it.
    – StoneGiant
    Nov 13 '18 at 16:55










  • It should be all set now.
    – StoneGiant
    Nov 13 '18 at 17:01














0












0








0






If I'm guessing correctly at what you want, here's a way that uses a collection of e-mails by manager. They are created as you go, and then when you're finished, you can do whatever you want to the messages in the collection.



Dim allMessages as Collection
Dim currMessage as Object
Set allMessages = New Collection

For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If Cells(cell.Row, "G").Value = "4. Need Update"
' Find the e-mail for the present manager
For Each currMessage in allMessages
If currMessage.CC = cell.Value Then
Exit For
End If
Next currMessage

' Create it, if it wasn't found
If currMessage Is Nothing Then
Set currMessage = OutApp.CreateItem(0)
allMessages.Add currMessage
With currMessage
.CC = cell.Value
.Subject = "Résumé Needed"
.Body = "Howdy!" & vbNewLine & vbNewLine & "Body text."
End With
End If

' Add the Message Recipient and Attachment
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")
With currMessage
.To = .To & Iif(Len(.To) > 0,";","") & _
cell.Value & ", " & Cells(cell.Row, "D").Value
.Attachments.Add flpath & sSourcePath
End With

Set currMessage = Nothing

End If
Next cell

' Now do something with the messages.
For Each currMessage In allMessages
currMessage.Display
End If

Set currMessage = Nothing
Set allMessages = Nothing


Caveat: Given that I don't have your data and don't use Outlook presently, I have not tested the above code snippet. The snippet primarily replaces your For...NextLoop, with an additional loop and clean up at the end, some declarations at the beginning. Let me know if it gives you problems, and I'll try to fix this answer based on what you tell me.






share|improve this answer














If I'm guessing correctly at what you want, here's a way that uses a collection of e-mails by manager. They are created as you go, and then when you're finished, you can do whatever you want to the messages in the collection.



Dim allMessages as Collection
Dim currMessage as Object
Set allMessages = New Collection

For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If Cells(cell.Row, "G").Value = "4. Need Update"
' Find the e-mail for the present manager
For Each currMessage in allMessages
If currMessage.CC = cell.Value Then
Exit For
End If
Next currMessage

' Create it, if it wasn't found
If currMessage Is Nothing Then
Set currMessage = OutApp.CreateItem(0)
allMessages.Add currMessage
With currMessage
.CC = cell.Value
.Subject = "Résumé Needed"
.Body = "Howdy!" & vbNewLine & vbNewLine & "Body text."
End With
End If

' Add the Message Recipient and Attachment
sSourcePath = Dir(flpath & Cells(cell.Row, "E").Value & " *.docx")
With currMessage
.To = .To & Iif(Len(.To) > 0,";","") & _
cell.Value & ", " & Cells(cell.Row, "D").Value
.Attachments.Add flpath & sSourcePath
End With

Set currMessage = Nothing

End If
Next cell

' Now do something with the messages.
For Each currMessage In allMessages
currMessage.Display
End If

Set currMessage = Nothing
Set allMessages = Nothing


Caveat: Given that I don't have your data and don't use Outlook presently, I have not tested the above code snippet. The snippet primarily replaces your For...NextLoop, with an additional loop and clean up at the end, some declarations at the beginning. Let me know if it gives you problems, and I'll try to fix this answer based on what you tell me.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 16:56

























answered Nov 12 '18 at 17:01









StoneGiant

885416




885416












  • Thank you! I'll give this a test. To answer your previous questions, I can certainly sort the sheet. Also, I am hoping to send one e-mail and cc: everyone who has the same manager, attaching all résumés. I just meant Col C or B, doesn't matter which to choose. C is likely better anyways. Thanks again, I'll see how this works!
    – LBJ
    Nov 12 '18 at 17:08










  • If you sort the sheet, you don't need the collection. You can sort by the column you want, and walk down through the list building your message. When the manager name changes, send the one you've built and start a new one. The code currently provided doesn't require the sheet to be sorted.
    – StoneGiant
    Nov 12 '18 at 17:21










  • The code is having compiling errors - it doesn't understand where the bottom End If in the first chunk is coming from: If Cells(cell.Row, "G").Value = "4. Need Update" ' Find the e-mail for the present manager For Each currMessage in allMessages If currMessage.CC = cell.Value Then Exit For End If End If It also doesn't understand the Next cell or End If right above the Next cell. Any insight?
    – LBJ
    Nov 12 '18 at 20:48












  • I put an End If at the end of the For loop instead of a Next. Sorry. I'll fix it.
    – StoneGiant
    Nov 13 '18 at 16:55










  • It should be all set now.
    – StoneGiant
    Nov 13 '18 at 17:01


















  • Thank you! I'll give this a test. To answer your previous questions, I can certainly sort the sheet. Also, I am hoping to send one e-mail and cc: everyone who has the same manager, attaching all résumés. I just meant Col C or B, doesn't matter which to choose. C is likely better anyways. Thanks again, I'll see how this works!
    – LBJ
    Nov 12 '18 at 17:08










  • If you sort the sheet, you don't need the collection. You can sort by the column you want, and walk down through the list building your message. When the manager name changes, send the one you've built and start a new one. The code currently provided doesn't require the sheet to be sorted.
    – StoneGiant
    Nov 12 '18 at 17:21










  • The code is having compiling errors - it doesn't understand where the bottom End If in the first chunk is coming from: If Cells(cell.Row, "G").Value = "4. Need Update" ' Find the e-mail for the present manager For Each currMessage in allMessages If currMessage.CC = cell.Value Then Exit For End If End If It also doesn't understand the Next cell or End If right above the Next cell. Any insight?
    – LBJ
    Nov 12 '18 at 20:48












  • I put an End If at the end of the For loop instead of a Next. Sorry. I'll fix it.
    – StoneGiant
    Nov 13 '18 at 16:55










  • It should be all set now.
    – StoneGiant
    Nov 13 '18 at 17:01
















Thank you! I'll give this a test. To answer your previous questions, I can certainly sort the sheet. Also, I am hoping to send one e-mail and cc: everyone who has the same manager, attaching all résumés. I just meant Col C or B, doesn't matter which to choose. C is likely better anyways. Thanks again, I'll see how this works!
– LBJ
Nov 12 '18 at 17:08




Thank you! I'll give this a test. To answer your previous questions, I can certainly sort the sheet. Also, I am hoping to send one e-mail and cc: everyone who has the same manager, attaching all résumés. I just meant Col C or B, doesn't matter which to choose. C is likely better anyways. Thanks again, I'll see how this works!
– LBJ
Nov 12 '18 at 17:08












If you sort the sheet, you don't need the collection. You can sort by the column you want, and walk down through the list building your message. When the manager name changes, send the one you've built and start a new one. The code currently provided doesn't require the sheet to be sorted.
– StoneGiant
Nov 12 '18 at 17:21




If you sort the sheet, you don't need the collection. You can sort by the column you want, and walk down through the list building your message. When the manager name changes, send the one you've built and start a new one. The code currently provided doesn't require the sheet to be sorted.
– StoneGiant
Nov 12 '18 at 17:21












The code is having compiling errors - it doesn't understand where the bottom End If in the first chunk is coming from: If Cells(cell.Row, "G").Value = "4. Need Update" ' Find the e-mail for the present manager For Each currMessage in allMessages If currMessage.CC = cell.Value Then Exit For End If End If It also doesn't understand the Next cell or End If right above the Next cell. Any insight?
– LBJ
Nov 12 '18 at 20:48






The code is having compiling errors - it doesn't understand where the bottom End If in the first chunk is coming from: If Cells(cell.Row, "G").Value = "4. Need Update" ' Find the e-mail for the present manager For Each currMessage in allMessages If currMessage.CC = cell.Value Then Exit For End If End If It also doesn't understand the Next cell or End If right above the Next cell. Any insight?
– LBJ
Nov 12 '18 at 20:48














I put an End If at the end of the For loop instead of a Next. Sorry. I'll fix it.
– StoneGiant
Nov 13 '18 at 16:55




I put an End If at the end of the For loop instead of a Next. Sorry. I'll fix it.
– StoneGiant
Nov 13 '18 at 16:55












It should be all set now.
– StoneGiant
Nov 13 '18 at 17:01




It should be all set now.
– StoneGiant
Nov 13 '18 at 17:01


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265774%2fsend-email-to-multiple-people-based-on-common-cell-value-using-excel-vba%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values