![](/img/trans.png)
[英]Excel Count number of times in range that cells in column A are less than corresponding cell in column B
[英]Excel VBA script to count the number of values in column A that are less than the values in Column B same row
Sub CompareValues()
Dim rng As Range
Dim cellA As Object
Dim cellB As Object
Dim count As Integer
Set rng = Selection
For Each cell In rng
'test if value in column A is less than in column B
If cellA.Value < cellB.Value Then
count += 1
End If
Next
End Sub
基本上,我有一個包含50列以上的電子表格,每個電子表格包含350行,其中大多數都是數字值(如果沒有結果,則這些值將是數字或NA)。 我希望能夠在每個列的底部生成一個計數,該計數告訴我一列中有多少個值小於上一列中的等效值。 因此,如果B3 <A3,則計數將增加。 但是,如果B3 = A3或B3> A3,則不會重復計數。 我知道我需要遍歷每個值並將其與上一列中同一行中的值進行比較,但是我對如何實際執行此操作相當迷惑。 任何幫助將不勝感激。謝謝。
僅使用公式的簡單解決方案。 在每一列的底部,例如在B351
您將使用數組公式:
=SUM(IF(A1:A350<=B1:B350,1,0))
請注意,這是通過按CTRL
+ SHIFT
+ ENTER
。 問候,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.