Select a range based on the current worksheet

Cease

Board Regular
Joined
Dec 28, 2010
Messages
112
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
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!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

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