I am trying to get email addresses from a worksheet(Sheet1) into the .To line for an outlook email based on the specific string value in the main worksheet.
I have managed to play with it several ways but none have given the results I need. The idea is that it checks a cell on the main worksheet for a specific string value, then would reference a specific range of cells in one column from another worksheet based on the string value and include these emails in the .To line, separated by a";".
I also noticed it removed data from the cells when it pulled it in testing, replacing some cells with "Column1"
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim emailRng As Range, cl As Range
Dim sTo As String
Set emailRng = Worksheets("SHEET1").Range("D3:D20")
For Each cl In emailRng
sTo = sTo & ";" & cl.Value
Next
sTo = Mid(sTo, 2)
If InStr(ActiveCell.Value, "ABC") > 0 Then
emailRng = ThisWorkbook.Sheets("SHEET1").Range("D3:D5")
ElseIf InStr(ActiveCell.Value, "XYZ") > 0 Then
emailRng = ThisWorkbook.Sheets("SHEET1").Range("D11:D15")
End If
If Target.CountLarge > 1 Then Exit Sub
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
Select Case Target.Column
Case Is = 15
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = sTo
.CC = "REQ@EMAIL.COM"
.Subject = ""
.HTMLBody = "Please attend "
.Display
End With
End Select
Application.ScreenUpdating = False
End Sub