I think you will need to use some if’s or selectcase. Test using this 

Sub selectcase()
Select Case ActiveCell.Column
Case Is = 14: x = "column 14"
Case Is = 15: x = "column 15"
Case Else
End Select
MsgBox x
End Sub


Don Guillett
Microsoft Excel Developer
SalesAid Software
[email protected]

From: Selva 
Sent: Friday, August 31, 2012 10:50 AM
To: [email protected] 
Subject: $$Excel-Macros$$ Need update on the attached Macro

Hi All,

 

Need an update on the attached macro file. Based on this file, whenever the 
Column N  drop down is selected for ‘Failure’, an outlook mail generates and 
ready to be sent. If ‘Success’ is selected no mails will be sent. But my issue 
is whenever I select for ‘Failure’ in Column O. Two mails are being generated 
for Column N and for Column O. But I want to restrict it to one mail for that 
cell which I have selected only. Can any one help me on this?

 

Code:-

 

Sub sendEmail()

 

    Dim objOL As Object

    Dim objMail As Object

    Dim sEmail As String

    Dim sEmailColumn As String

    Dim sSubject As String

    Dim sBody As String

    Dim lDataRow As Long

    Dim cl As Range

    'Set column with email address

    sEmailColumn = "Z"

     For Each cl In Selection.Resize(, 1)

        

        lDataRow = cl.Row

        

        If cl.Parent.Range("N" & lDataRow).Value = "Failure" Then

            With cl.Parent

                sEmail = .Range(sEmailColumn & lDataRow)

                sSubject = Range("B" & lDataRow)

                sBody = "URL/Test Condition: " & .Range("G" & lDataRow) & 
vbNewLine & "Step A" 

            End With

            

            On Error GoTo Cleanup

            

            Set objOL = CreateObject("Outlook.Application")

    

            Set objMail = objOL.CreateItem(0)

            With objMail

                .To = sEmail

                .Subject = sSubject

                .Body = sBody

                .Display

            End With

        End If

    Next cl

    For Each cl In Selection.Resize(, 1)

        

        lDataRow = cl.Row

        

        If cl.Parent.Range("O" & lDataRow).Value = "Failure" Then

            With cl.Parent

                sEmail = .Range(sEmailColumn & lDataRow)

                sSubject = Range("B" & lDataRow)

                sBody = "URL/Test Condition: " & .Range("G" & lDataRow) & 
vbNewLine & "STEP B" & vbNewLine & "<Insert Screenshots here>"

            End With

            

            On Error GoTo Cleanup

            

            Set objOL = CreateObject("Outlook.Application")

    

            Set objMail = objOL.CreateItem(0)

            With objMail

                .To = sEmail

                .Subject = sSubject

                .Body = sBody

                .Display

            End With

        End If

    Next cl

    For Each cl In Selection.Resize(, 1)

        

        lDataRow = cl.Row

        

        If cl.Parent.Range("P" & lDataRow).Value = "Failure" Then

            With cl.Parent

                sEmail = .Range(sEmailColumn & lDataRow)

                sSubject = Range("B" & lDataRow)

                sBody = "URL/Test Condition: " & .Range("G" & lDataRow) & 
vbNewLine & "STEP C" & vbNewLine & "<Insert Screenshots here>"

            End With

            

            On Error GoTo Cleanup

            

            Set objOL = CreateObject("Outlook.Application")

    

            Set objMail = objOL.CreateItem(0)

            With objMail

                .To = sEmail

                .Subject = sSubject

                .Body = sBody

                .Display

            End With

        End If

    Next cl

    For Each cl In Selection.Resize(, 1)

        

        lDataRow = cl.Row

        

        If cl.Parent.Range("Q" & lDataRow).Value = "Failure" Then

            With cl.Parent

                sEmail = .Range(sEmailColumn & lDataRow)

                sSubject = Range("B" & lDataRow)

                sBody = "URL/Test Condition: " & .Range("G" & lDataRow) & 
vbNewLine & "STEP D" & vbNewLine & "<Insert Screenshots here>"

            End With

            

            On Error GoTo Cleanup

            

            Set objOL = CreateObject("Outlook.Application")

    

            Set objMail = objOL.CreateItem(0)

            With objMail

                .To = sEmail

                .Subject = sSubject

                .Body = sBody

                .Display

            End With

        End If

    Next cl

 

Regards,

Selva Jayapal

Accenture - IDC, Chennai

PMO - Operations

Desk - +91 44 426 70619

Mobile - +91 7708658033

Office Communicator : [email protected]

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES (1120+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 
 
6) Jobs posting is not allowed.
 
7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
 
 

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].


Reply via email to