zacheria77
New Member
- Joined
- Nov 30, 2017
- Messages
- 1
Hello,I'm new to VBA and am having difficulties email a range of cells based on a set of conditions. I am trying to modify the code that I found here https://www.rondebruin.nl/win/s1/outlook/bmail2.htm to do the following: (1) Only include rows returning a "Yes" value in Column Y, (2) Only include rows which have a matching value in Column I, and (3) Hide all columns except C, D, G, S, and T. Column Y returns a "Yes" if the condition for a reminder have been met and Column I includes the intended recipient. I want each recipient to include one email for every row which meets the condition in Column Y. The code works as designed I am just unable to modify the range to allow for my conditions. As modified, it emails the entire table and then hides certain columns in the source sheet. Copy of the modified code: Sub LateReviewEmail_Click() Dim OutApp As Object, OutMail As Object Dim rng As Range Dim StrBody As String StrBody = "" & _ "Hello,
" & _ "This is a reminder that the following deliverables are pending your review:
" StrBody1 = "
Please complete your review and submit back to the Deliverable Monitor with your recommendation as soon as possible." & _ "
Regards," & _ "
" & _ "
Contract Management" & _ Application.ScreenUpdating = False Set OutApp = CreateObject("Outlook.Application") LastRow = Cells(Cells.Rows.Count, "Y").End(xlUp).Row On Error Resume Next Set rng = Sheets("Deliverable Management").Range("B4:AB" & LastRow).SpecialCells(xlCellTypeVisible) If Cells(Cell.Row, "Y").value = "No" Then _ EntireRow.Hidden = True Range("B5,E5,F5,H5,I5,J5,K5,L5,M5,N5,O5,P5,Q5,R5,V5,W5,X5,Y5,Z5,AA5,AB5").EntireColumn.Hidden = True On Error GoTo cleanup Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = "" .CC = "" .Subject = "Late Review" .Importance = olImportanceHigh .HTMLBody = StrBody & RangetoHTML(rng) & StrBody1 .SentOnBehalfofName = "" .Display End With On Error GoTo 0 Set OutMail = Nothingcleanup: Set OutApp = Nothing Application.ScreenUpdating = TrueEnd Sub
" & _ "This is a reminder that the following deliverables are pending your review:
" StrBody1 = "
Please complete your review and submit back to the Deliverable Monitor with your recommendation as soon as possible." & _ "
Regards," & _ "
" & _ "
Contract Management" & _ Application.ScreenUpdating = False Set OutApp = CreateObject("Outlook.Application") LastRow = Cells(Cells.Rows.Count, "Y").End(xlUp).Row On Error Resume Next Set rng = Sheets("Deliverable Management").Range("B4:AB" & LastRow).SpecialCells(xlCellTypeVisible) If Cells(Cell.Row, "Y").value = "No" Then _ EntireRow.Hidden = True Range("B5,E5,F5,H5,I5,J5,K5,L5,M5,N5,O5,P5,Q5,R5,V5,W5,X5,Y5,Z5,AA5,AB5").EntireColumn.Hidden = True On Error GoTo cleanup Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = "" .CC = "" .Subject = "Late Review" .Importance = olImportanceHigh .HTMLBody = StrBody & RangetoHTML(rng) & StrBody1 .SentOnBehalfofName = "" .Display End With On Error GoTo 0 Set OutMail = Nothingcleanup: Set OutApp = Nothing Application.ScreenUpdating = TrueEnd Sub