Results 1 to 10 of 26

Thread: Macro to check values based on certain text

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14

    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
    Last edited by Admin; 10-18-2012 at 07:55 AM. Reason: code tag added

Similar Threads

  1. Sum values based on multiple criteria
    By Jorrg1 in forum Excel Help
    Replies: 8
    Last Post: 01-07-2013, 03:04 PM
  2. Replies: 10
    Last Post: 12-10-2012, 11:28 PM
  3. Offset based on Values in Column E
    By mrmmickle1 in forum Excel Help
    Replies: 7
    Last Post: 12-04-2012, 10:06 AM
  4. Macro to clear data based on color fill
    By Howardc in forum Excel Help
    Replies: 7
    Last Post: 12-03-2012, 09:25 AM
  5. Loop and Check For Values In Entire Column in Excel
    By Jeff5019 in forum Excel Help
    Replies: 3
    Last Post: 05-01-2012, 10:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •