Macro to check values based on certain text
I have the word "Check" in Column A. Where Check appears in cloumn A I would like to determine whether the values in the same row as where "check" appears <> (not equal) to zero. This needs to be checked on all sheets, except the sheet "Consolidated"
I have code to do this, but when running the code, I get an error message "unable to get the sum property of the worksheet function class" -the folowing code is highlighted when I click on Debug
If Application.WorksheetFunction.Sum(myrange) <> 0 Then
The full code is
Code:
Sub Check_Variance()
Dim sh
Dim caddress As String, lastrowSH1 As Long
Dim startcell As Range, endcell As Range, myrange As Range
For Each sh In Worksheets
If UCase(sh.Name) <> "CONSOLIDATED" Then
caddress = ""
lastrowSH1 = Sheets(sh.Name).Range("A" & Rows.Count).End(xlUp).Row
For Each cell In Sheets(sh.Name).Range("A1:A" & lastrowSH1)
Debug.Print sh.Name
Debug.Print cell.Value
If UCase(cell.Value) = "CHECK" Then
Set startcell = Sheets(sh.Name).Range("B" & cell.Row)
Set endcell = Sheets(sh.Name).Range("Q" & cell.Row)
Set myrange = Sheets(sh.Name).Range(startcell, endcell)
If Application.WorksheetFunction.Sum(myrange) <> 0 Then
For i = 1 To 26
If cell.Offset(0, i) <> 0 Then
If caddress = "" Then
caddress = cell.Offset(0, i).Address
Else
caddress = caddress & ", " & cell.Offset(0, i).Address
End If
End If
Next i
End If
End If
Next cell
If caddress <> "" Then
MsgBox "Please check the following address(es) on " & sh.Name & vbNewLine & vbNewLine & caddress
End If
End If
Next sh
End Sub