Help!! I have been tasked with sending excel comment data to an email when there are issues with generators or fuel tanks. Never have used Visual basic before! Found ideas and it works but there has to be an easier way?This is from the fuel log and had to move excel columns to kind of make work because i couldnt figure out how to get data after the comment cell. I tried looping, but could not figure out. Data range is (J7:M13) and (A58:M63). Thanks!!
Dim xRg As Range
'Updated by Extendoffice 2017/9/12
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("L7")
Set xRg = Range("M7")
Set xRg = Range("J7")
If xRg = Target And Target.Value > 50 Then
Call Send_Range
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("J8")
If xRg = Target And Target.Value > 50 Then
Set xRg = Range("L8")
Set xRg = Range("M8")
Call Send_Range
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("J9")
If xRg = Target And Target.Value > 50 Then
Set xRg = Range("L9")
Set xRg = Range("M9")
Call Send_Range
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("J10")
If xRg = Target And Target.Value > 50 Then
Set xRg = Range("L10")
Set xRg = Range("M10")
Call Send_Range
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("J11")
If xRg = Target And Target.Value > 50 Then
Set xRg = Range("L11")
Set xRg = Range("M11")
Call Send_Range
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("J12")
If xRg = Target And Target.Value > 50 Then
Set xRg = Range("L12")
Set xRg = Range("M12")
Call Send_Range
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("J13")
If xRg = Target And Target.Value > 50 Then
Set xRg = Range("L13")
Set xRg = Range("M13")
Call Send_Range
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("A59")
Set xRg = Range("H59")
Set xRg = Range("L59")
Set xRg = Range("M59")
If xRg = Target And Target.Value > 50 Then
Call Send_Range_1
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("A60")
Set xRg = Range("H60")
Set xRg = Range("L60")
Set xRg = Range("M60")
If xRg = Target And Target.Value > 50 Then
Call Send_Range_1
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("A61")
Set xRg = Range("H61")
Set xRg = Range("L61")
Set xRg = Range("M61")
If xRg = Target And Target.Value > 50 Then
Call Send_Range_1
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("A62")
Set xRg = Range("H62")
Set xRg = Range("L62")
Set xRg = Range("M62")
If xRg = Target And Target.Value > 50 Then
Call Send_Range_1
End If
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Range("A63")
Set xRg = Range("H63")
Set xRg = Range("L63")
Set xRg = Range("M63")
If xRg = Target And Target.Value > 50 Then
Call Send_Range_1
End If
End Sub
Sub Send_Range()
' Select the range of cells on the active worksheet.
ActiveSheet.Range("J6:M13").Select
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = True
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To and Subject lines. Finally the message
' is sent.
With ActiveSheet.MailEnvelope
.Introduction = "Bradley Booster Fuel Weekly Remarks."
.Item.To = "whartsnet.net.com"
.Item.Subject = "Bradley Booster Fuel Weekly Remarks"
.Item.Send
End With
End Sub
Sub Send_Range_1()
' Select the range of cells on the active worksheet.
ActiveSheet.Range("A58:M63").Select
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = True
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To and Subject lines. Finally the message
' is sent.
With ActiveSheet.MailEnvelope
.Introduction = "Bradley Booster Fuel Condition and Action Taken."
.Item.To = "whart@ctwater.com"
.Item.Subject = "Bradley Booster Fuel Condition and Action Taken"
.Item.Send
End With
End Sub