我有多个列包含下面列出的示例信息:
A | B | C | D
------------------------
23R | 12C | 4D | 35R
12C | 76T | 14T | 19D
32C | 56D | 14R | 68D
... | ... | ... | ...
etc | etc | etc | etc
从整个表格(不创建另一列),我想总结包含字母“R”的所有值。鉴于上面的示例表,数字应为:72。我尝试了多种不同的方法:
如何在没有任何其他列的情况下实现此目的?单元格也可以是空白的,如果可能,我想将它们作为零处理。
答案 0 :(得分:6)
使用此数组公式:
=SUM(IF(RIGHT(A2:D4,1)="R",VALUE(LEFT(A2:D4,LEN(A2:D4)-1)),0))
A2:D4是你的整个表格。按Ctrl + Shift + Enter键输入公式。
答案 1 :(得分:1)
Excellll提供了一种很好的配方方式。这是一个VBA函数,它将执行相同的操作。你会这样称呼它:
=CountR(A2:D4) 'in your example becomes 72
代码:
Function CountR(ByVal cell_range As Range) As Long
Dim i As Long, j As Long, total As Long
Dim varray As Variant
varray = cell_range.Value
For i = 1 To UBound(varray, 1)
For j = 1 To UBound(varray, 2)
If Right$(varray(i, j), 1) = "R" Then
total = total + Left$(varray(i, j), Len(varray(i, j)) - 1)
End If
Next
Next
CountR = total
End Function