Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 26

Thread: Macro to check values based on certain text

  1. #11
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    hi

    Code:
    If Evaluate("abs(sumif(" & myRange.Address(external:=1) & ",{"">0"",""<0""}))") > 0.0001 Then
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  2. #12
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Thanks very much for the help. Code works perfectly

  3. #13
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Hi

    You helped me a while ago with a macro that finds the text 'check" and column A and if the value in the rows that are in line with "Check" is <0 or > 0 , then a message box must pop advise the cell number that there are variance the tolerance is 0.00001. The macro works well where there are postive variances, but does not pick up the negative variances.

    See code below for ease of reference

    Your assistance inresolving this will be most appreciated
    HTML Code:
    Sub Check_Variance()
        Dim sh  As Worksheet, cCell As Range
        Dim cAddress As String, lastRowSH1 As Long, i As Long
        Dim startCell As Range, endCell As Range, myRange As Range
    
    
        For Each sh In Worksheets
            If UCase(sh.Name) <> "CONSOLIDATED" Then
                cAddress = ""
                
                With sh
                    lastRowSH1 = .Range("B" & .Rows.Count).End(xlUp).Row
                    For Each cCell In .Range("A1:A" & lastRowSH1)
                        Debug.Print sh.Name
                        Debug.Print cCell.Value
                        If UCase(cCell.Value) = "CHECK" Then
                            Set startCell = .Range("B" & cCell.Row)
                            Set endCell = .Range("Z" & cCell.Row)
                            Set myRange = .Range(startCell, endCell)
        
                        If Evaluate("abs(sumif(" & myRange.Address(external:=1) & ",{"">0"",""<0""}))") > 0.00001 Then
                                For i = 1 To 26
                                    If cCell.Offset(0, i) <> 0 Then
                                        If cAddress = "" Then
                                            cAddress = cCell.Offset(0, i).Address
                                        Else
                                            cAddress = cAddress & ", " & cCell.Offset(0, i).Address
                                        End If
                                    End If
                                Next i
                            End If
                        End If
                    Next cCell
                    If cAddress <> "" Then
                        MsgBox "Please check the following address(es) on " & sh.Name & vbNewLine & vbNewLine & cAddress
                    End If
                End With
            End If
        Next sh
    End Sub

  4. #14
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Try

    Code:
    If Evaluate("sumproduct(--(abs(" & myRange.Address(external:=1) & ")>0.0001)," & myRange.Address(external:=1) & ")") Then
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #15
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Thanks for the reply. When running the macro, it comes up with type mismatch 13

    I picked up one small error, ) before >0.00001 but it still does not solve the problem. It would be appreciated if you would check & correct

    If Evaluate("sumproduct(--(abs(" & myRange.Address(external:=1) & "(>0.0001)," & myRange.Address(external:=1) & ")") Then

  6. #16
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Howardc, what admin has posted is working fine on the sample file you've attached. Also, the bracket should be ), and not the other way around.

    Once again,
    Code:
    Evaluate("sumproduct(--(abs(" & myRange.Address(external:=1) & ")>0.0001)," & myRange.Address(external:=1) & ")")
    is correct. Do you want to attach a sample file again, in case this is not working?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  7. #17
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Hi Excelfox

    Thanks for the reply. See full code below

    When running the macro, it comes up with "type mismatch 13" and the folowing code is highlighted


    If cCell.Offset(0, i) <> 0 Then

    It would be appreciated if you could assist me






    Code:
    sub Check_Variance()
                Dim sh  As Worksheet, cCell As Range
                Dim cAddress As String, lastRowSH1 As Long, i As Long
                Dim startCell As Range, endCell As Range, myRange As Range
    
    
                For Each sh In Worksheets
                    If UCase(sh.Name) <> "CONSOLIDATED" Then
                        cAddress = ""
                        
                        With sh
                            lastRowSH1 = .Range("B" & .Rows.Count).End(xlUp).Row
                            For Each cCell In .Range("A1:A" & lastRowSH1)
                                Debug.Print sh.Name
                                Debug.Print cCell.Value
                                If UCase(cCell.Value) = "CHECK" Then
                                    Set startCell = .Range("B" & cCell.Row)
                                    Set endCell = .Range("Z" & cCell.Row)
                                    Set myRange = .Range(startCell, endCell)
                
                              Evaluate("sumproduct(--(abs(" & myRange.Address(external:=1) & ")>0.0001)," & myRange.Address(external:=1) & ")") 
                               
                                        For i = 1 To 26
                                            If cCell.Offset(0, i) <> 0 Then
                                                If cAddress = "" Then
                                                    cAddress = cCell.Offset(0, i).Address
                                                Else
                                                    cAddress = cAddress & ", " & cCell.Offset(0, i).Address
                                                End If
                                            End If
                                        Next i
                                    End If
                                
                            Next cCell
                            If cAddress <> "" Then
                                MsgBox "Please check the following address(es) on " & sh.Name & vbNewLine & vbNewLine & cAddress
                            End If
                        End With
                    End If
                Next sh
            End Sub
    Last edited by Admin; 11-01-2012 at 05:32 PM.

  8. #18
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Howard,

    Please add code tags while posting code. This time I added for you.

    this line
    Code:
    Evaluate("sumproduct(--(abs(" & myRange.Address(external:=1) & ")>0.0001)," & myRange.Address(external:=1) & ")")
    should write as
    Code:
    If Evaluate("sumproduct(--(abs(" & myRange.Address(external:=1) & ")>0.0001)," & myRange.Address(external:=1) & ")")  Then
    also add an End If after Next i
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  9. #19
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Thanks for the help, much appreciated

  10. #20
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Hi Admin

    I picked up that if the first value in say column B in line with the text "check" is negative, the row number is not displayed. However, if postive the row number is displayed. It would be appreciated if you could amend the code to incorporate this

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
  •