Consulting

Results 1 to 4 of 4

Thread: Condition should applied if columns total value is not match

  1. #1
    VBAX Regular
    Joined
    Apr 2019
    Posts
    17
    Location

    Condition should applied if columns total value is not match

    Hi,

    In attached excel file sheet there are two columns dedicated for net and vat amount and ultimately the gross amount is comprises by totaling the Net+Vat amount. That means

    Net + Vat = Gross amount. If the Gross amount is not matching with sum of Net + Vat then cell interior color should be red.

    For better outlook I already change interior color of cell D4 and D5. The total gross amount is not matching with Net+Vat amount.

    I want to achieve this process through Macro.

    Regards,
    Shamim
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Public Sub FlagNonMatching()
    Dim lastrow As Long
    
        With ActiveSheet
        
            lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
            
            With .Range("D2").Resize(lastrow - 1)
            
                .FormatConditions.Add Type:=xlExpression, Formula1:="=D2<>B2+c2"
                .FormatConditions(1).Interior.Color = vbRed
            End With
        End With
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Apr 2019
    Posts
    17
    Location
    Thanks for the prompt response. Can this be done with Msgbox prompt " Different found in Column D"?

    Regards,
    Shamim
    Last edited by shamim; 05-18-2019 at 08:12 AM.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Public Sub FlagNonMatching()
    Const FORMULA_CHECK As String = "SUMPRODUCT(--(B2:B<lastrow>+C2:C<lastrow>=D2:D<lastrow>))=COUNT(D2:D<lastrow>)"
    Dim lastrow As Long
    
        With ActiveSheet
        
            lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
            
            With .Range("D2").Resize(lastrow - 1)
            
                .FormatConditions.Add Type:=xlExpression, Formula1:="=D2<>B2+c2"
                .FormatConditions(1).Interior.Color = vbRed
            End With
            
            If Not .Evaluate(Replace(FORMULA_CHECK, "<lastrow>", lastrow)) Then
            
                MsgBox "Differences detected", vbOKOnly, "Check Am,ounts"
            End If
        End With
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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