VBA change condition and send email using loop?

Jonesy27

New Member
Joined
Jul 15, 2016
Messages
5
Good afternoon,

I have 2 separate bits of code that work for a specified row, but I don't want to have to write it 100 times.

the first is this one:
Sub worksheet_change(ByVal target As Range)
Set target = Range("G3")
If target.Value = Range("O1") Then
Call sendtest2
End If
Set target = Range("G3")
If target.Value = Range("o1") Then
target.Value = "Requested"
End If
Set target = Range("G3")
If target.Value = Range("o2") Then
Call sendtest2
End If
Set target = Rang
If target.Value = Range("o2") Then
target.Value = "Cancelled"
End If

End Sub

which looks at a specific cell and runs a separate module (to compile and send the email) and then changes the value of that cell.

is there anyway to loop this for each row.


secondly, the email code looks at the given row. again, is there anyway to loop this?



Sub sendtest2()

Dim cell As Range
With CreateObject("outlook.<wbr>application").Createitem(0)
.to = "user@email.com"

.Subject = Range("u1") & "***TEST***-Airfield Request:- " & Range("a3") & " " & Range("U1")
.body = "Airfield Request:- " & Range("u1") & vbNewLine & "Requested by:- " & Range("F3") & vbNewLine & "ICAO:- <wbr> " & Range("a3") & vbNewLine & "Dest/Alt:- <wbr> " & Range("b3") & vbNewLine & "Type of operation:- " & Range("c3") & vbNewLine & "Intended month of operation:- " & Range("d3") & vbNewLine & vbNewLine & "Comments:- " & Range("e3")
.display
End With

End Sub


many thanks in advance
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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