![](/img/trans.png)
[英]How to check values in each cell from one column to each cell in another column
[英]How to check if Cell values balance each other
您可以使用條件公式,使用以下公式(僅適用於第一行)來執行此操作:
=OR(A1+B1=0;B1+C1=0;C1+D1=0)
此公式檢查兩個相鄰單元格的總和是否等於零,這是另一種表示它們應具有相同值但符號相反的方式。
顯然,您可以考慮更改此公式,例如:
代替:
A1+B1=0
你把:
AND(A1+B1=0;A1<>0)
當兩個值的總和等於零且其中至少一個不為零時,則兩者都不為零。
所有這些都在一個公式中得出:
=OR(AND(A1+B1=0;A1<>0);AND(B1+C1=0;B1<>0);AND(C1+D1=0;C1<>0))
在單元格E1
的條件格式中使用這樣的公式,並將其應用於E
列中的所有單元格。
嘗試:
Option Explicit
Sub test()
Dim Row As Long, Column As Long
Dim rng As Range
'Let us assume that we use Sheet1 & columns A to F
With ThisWorkbook.Worksheets("Sheet1")
For Row = 2 To 100 ' <- Let us assume that data starts in row 2 and ends in row 100
Set rng = .Range("B" & Row & ":E" & Row)
For Column = 2 To 6
If .Cells(Row, Column).Value <> 0 Then
If Application.WorksheetFunction.CountIf(rng, (-1 * .Cells(Row, Column).Value)) > 0 Then
.Range("F" & Row).Interior.Color = vbBlue
Exit For
End If
End If
Next Column
Next Row
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.