I am trying to run two worksheet_change event codes on the same worksheet. One to move completed rows to another worksheet and the other one to send emails based on value in another cell. The email code works.
The completed row move raises
Run-Time error '424' Object required.
When I debug it highlights the If Target.Cells.Count > 1 Then
line in Worksheet_change2
. Both codes run individually fine.
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheet_Change1 Target
Worksheet_Change2 Target
End Sub
Sub Worksheet_Change1(ByVal Target As Range)
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
A = Worksheets("Working").UsedRange.Rows.Count
B = Worksheets("Completed").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Completed").UsedRange) = 0 Then B = 0
End If
Set xRg = Worksheets("Working").Range("I1:I" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Done" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("Completed").Range("A" & B + 1)
xRg(C).EntireRow.Delete
If CStr(xRg(C).Value) = "Done" Then
C = C - 1
End If
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub
Sub Worksheet_Change2(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If (Not Intersect(Target, Range("G:G")) Is Nothing) And (Target.Value = "MOBILARIS") Then
Call Mail_small_Text_Outlook1
End If
If (Not Intersect(Target, Range("G:G")) Is Nothing) And (Target.Value = "COMMS TECH") Then
Call Mail_small_Text_Outlook2
End If
If (Not Intersect(Target, Range("G:G")) Is Nothing) And (Target.Value = "PLANNING ENGINEER") Then
Call Mail_small_Text_Outlook3
If Target.Cells.Count > 1 Then Exit Sub
End If
End Sub
Sub Mail_small_Text_Outlook1()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi" & vbNewLine & vbNewLine & _
"Please check the Comms Issue Register, there has been an issue reported regarding Mobilaris" & vbNewLine & _
"Thankyou"
On Error Resume Next
With xOutMail
.To = "xxxx"
.CC = ""
.BCC = ""
.Subject = "Mobilaris Issue"
.Body = xMailBody
.Send 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Sub Mail_small_Text_Outlook2()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi" & vbNewLine & vbNewLine & _
"Please check the Comms Issue Register, there has been an issue reported with comms somewhere UG" & vbNewLine & _
"Thankyou"
On Error Resume Next
With xOutMail
.To = "xxxx"
.CC = ""
.BCC = ""
.Subject = "Communications Issue"
.Body = xMailBody
.Send 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Sub Mail_small_Text_Outlook3()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi" & vbNewLine & vbNewLine & _
"Please check the Comms Issue Register, there is Leaky Feeder extensions that are needed to be scheduled" & vbNewLine & _
"Thankyou"
On Error Resume Next
With xOutMail
.To = "xxxxx"
.CC = ""
.BCC = ""
.Subject = "Leaky Feeder extensions required"
.Body = xMailBody
.Send 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub