Hey guys, I've seen posts similar to this, but I can't seem to find them.
I have the following code and need to alter it to select certain cells based on the value of a certain cell.
example I have cell a1 named after the sheet it is on, and that is also the name of the worker I want to look up, and mail corresponding information via outlook.
so if cell A1 on worksheet 'Worker2' says Worker2
then on the sheet this code is on has
c3 = Worker1
c4 = Worker2
c5 = Worker3
with worker information in adjacent cells D3:D5
how do I make this code mail information just for Worker2
I know how to set it up if it were a function, like vlookup, or using index match, but I don't know how to apply that knowledge into the code.
Any help or direction would be greatly appreciated, and thanks in advance!
I have the following code and need to alter it to select certain cells based on the value of a certain cell.
example I have cell a1 named after the sheet it is on, and that is also the name of the worker I want to look up, and mail corresponding information via outlook.
so if cell A1 on worksheet 'Worker2' says Worker2
then on the sheet this code is on has
c3 = Worker1
c4 = Worker2
c5 = Worker3
with worker information in adjacent cells D3:D5
how do I make this code mail information just for Worker2
Code:
Sub SendEmail2()
Dim OutlookApp As Object
Dim MItem As Object
Dim cell As Range
Dim email_ As String
Dim subject_ As String
Dim body_ As String
Dim attach_ As String
'Create Outlook object
Set OutlookApp = CreateObject("Outlook.Application")
' Loop through the rows
For Each cell In Range("a3:a5").Cells.SpecialCells(xlCellTypeConstants)
email_ = cell.Value
subject_ = cell.Offset(0, 1).Value
body1_ = Cells.Range("c3").Value
body2_ = Cells.Range("d3").Value
'Create Mail Item and send it
Set MItem = OutlookApp.CreateItem(0)
With MItem
.To = email_
.Subject = subject_
.Body = body1_ & vbNewLine & body2_
.Display
End With
Next
End Sub
I know how to set it up if it were a function, like vlookup, or using index match, but I don't know how to apply that knowledge into the code.
Any help or direction would be greatly appreciated, and thanks in advance!