I have been using the following macro, which works very well indeed, but it has come to the point where it needs some enhancements:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myMail As String

If Target.Column = 7 Then

    If Target.Value = "option 1" Then
        myMail = "email1"
    ElseIf Target.Value = "option 2" Then
        myMail = "email2"
    ElseIf Target.Value = "option 3" Then
        myMail = "email3"
    ElseIf Target.Value = "option 4" Then
        myMail = "email4"
    ElseIf Target.Value = "option 5" Then Exit Sub

    End If

    With CreateObject("Outlook.Application").CreateItem(0)
        .To = myMail
        .Subject = "Hello"
        .Body = "Hi," & vbNewLine & vbNewLine & "This is a test"
    End With
End If
End Sub

The "options" are selected from a drop down list contained in each cell in column 7 (it wouldn't let me use "G"). Upon selecting one of the options, an email is automatically generated.

I would now like to add to the subject line of the email, the value of the cell from column "A" in the same row. eg. If option 3 is selected in cell G15, the value from cell A15 needs to be added to the subject line of the email.

As well as this, a further enhancement is needed:

As the worksheet is likely to grow into 100's of lines I would like the macro to generate a hyperlink which links to the exact cell in column "A" (from where the value added to the email subject line was taken). This hyperlink then needs to be automatically added to the body of the email.

New contributor
GlynB is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • You have posted working code. It would be prefered to include your attempted changes to this code that adress the needs you have. And tell us what part you got stuck on. That way it's easier to help. Just a simple headsup; Target.Row would tell you the exact (or rather first) line of the changed cell/range. – JvdV Aug 12 at 12:26
  • As yet I have not made any attempts to change this code as I wouldn't know where to start. – GlynB Aug 12 at 13:32

Your Answer

GlynB is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.