Dynamic email recipient list based on cell colour VBA

Lisa05

New Member
Joined
Nov 25, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hello All,
I have a macro created to send an email straight from the Excel file including Excel table in an email body. I have a question on the recipient list. Right now I fill in recepient list manually. But the recipients to whom an email should be sent are included in the Excel table pasted into mail body. Those cells in the table which include people to whom an email should be send are coloured red. Is it possible to create a condition to search for the red coloured cells within the table and add the value to the recepient list?
Thank you in advance for help.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
you can loop through the table checking the cells for colour and then add the contents to a recipient list. If you could attach a sample table and confirm if they are always in the same place
 
Upvote 0
you can loop through the table checking the cells for colour and then add the contents to a recipient list. If you could attach a sample table and confirm if they are always in the same place
Thank you for reply gordsky.

Attached is the example of the table. The email shall be send only to recpients in red. Also, there will be additional columns each month.
 

Attachments

  • TableExample.PNG
    TableExample.PNG
    9.2 KB · Views: 13
Upvote 0
Thank you for reply gordsky.

Attached is the example of the table. The email shall be send only to recpients in red. Also, there will be additional columns each month.
will the people to be emailed in red always be in the LAST COLUMN
 
Upvote 0
No, it can be either last or any prior columns
try this.
You will need to change "TableName" in the code to be the actual name of your table.
Then in your email code change the "TO" line to = recip

It works on the standard red. If you have used a lightly different colour it wont pick them up. You could however just get the RGB colour for the colour you want to use and change the vbRed reference in the code to be RGB(num,num,num) where num are the three RGB code numbers

VBA Code:
Sub MailList()

Dim tbl As ListObject
Dim col As Long
Dim c As range
Dim recip As String

Set tbl = ActiveSheet.ListObjects("TableName")
col = tbl.range.Columns.count

'  change "TableName" to be the name of your table
   For Each c In ActiveSheet.ListObjects("TableName").range

      If c.Interior.Color = vbRed Then
         recip = recip & ";" & c.Value
        
      End If
    
   Next c

End Sub
 
Upvote 0
Solution
try this.
You will need to change "TableName" in the code to be the actual name of your table.
Then in your email code change the "TO" line to = recip

It works on the standard red. If you have used a lightly different colour it wont pick them up. You could however just get the RGB colour for the colour you want to use and change the vbRed reference in the code to be RGB(num,num,num) where num are the three RGB code numbers

VBA Code:
Sub MailList()

Dim tbl As ListObject
Dim col As Long
Dim c As range
Dim recip As String

Set tbl = ActiveSheet.ListObjects("TableName")
col = tbl.range.Columns.count

'  change "TableName" to be the name of your table
   For Each c In ActiveSheet.ListObjects("TableName").range

      If c.Interior.Color = vbRed Then
         recip = recip & ";" & c.Value
       
      End If
   
   Next c

End Sub
Thank you so much, itworked!
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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