Hi,
I have a spreadsheet generated by Microsoft Forms that updates information in new rows everytime the form is submitted.
Column C contains the submitter's email address. When the request has been completed, I enter the "Date Completed" in Column S. When I enter this information, I want it to send an email to the email address located in Column B. The Subject needs to be the information in Column H and the body needs to include information from Column T.
I also want the loop to go from i = 2 to the last used cell but do not know how to reference this.
This is what I have so far but no matter where I fill out the information in Column S, it only takes the information from row 2. If the date is entered in S15, for example, then it needs to use the email address from C15 and the information from H15 and T15. Is there a way to do this??
This is what I have so far (I used i = 2 to 1000 arbitrarily because I could not figure this part out). It works this way, but then it takes way too long to finish the loop and sometimes freezes Excel. Is there a way to shorten this range for something like i = 2 to (Last Used Row).
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRgSel As Range
Dim xOutApp As Object
Dim xMailItem As Object
Dim xMailBody As String
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xRg = Range("S:S")
Set xRgSel = Intersect(Target, xRg)
ActiveWorkbook.Save
For i = 2 To 1000
If Not xRgSel Is Nothing Then
Set xOutApp = CreateObject("Outlook.Application")
Set xMailItem = xOutApp.CreateItem(0)
xMailBody = "Purification " & Cells(i, 8).Value & " is Complete." & vbNewLine & vbNewLine & "The following method was used: " & Cells(i, 20).Value
With xMailItem
.To = Cells(i, 3).Value
.Subject = "Purification " & Cells(i, 8).Value & " is Complete"
.Body = xMailBody
.Display
End With
Set xRgSel = Nothing
Set xOutApp = Nothing
Set xMailItem = Nothing
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Next
End Sub
Thanks for your insight!
Bookmarks