[英]Check excel column values if they are equal to each other
I have a table like this 我有这样的桌子
Product Price Currency 产品价格货币
________ _____ ________ ________ _____ ________
Product 1 10 USD 商品1 10 USD
Product 2 11 EUR 商品2 11 EUR
Product 3 12 USD 产品3 12 USD
Product 4 13 CNY 商品4 13 CNY
Product 5 14 EUR 产品5 14 EUR
_____ _____
=subtotal(109) =小计(109)
I use filter in Currency column, and subtotal(109) formula in price column to sum prices. 我在“货币”列中使用过滤器,在“价格”列中使用小计(109)公式对价格求和。 So if USD is selected from filter, it filters all products with USD price and sums them.
因此,如果从过滤器中选择了美元,它将过滤所有具有美元价格的产品并对其求和。 But if currency is not filtered subtotal(109) sums prices anyway, which is wrong (USD 1 + EUR 1 is not 2).
但是,如果未对货币进行过滤,小计(109)仍将对价格求和,这是错误的(1美元+ 1欧元不是2)。
I want to fire subtotal(109) formula only if values in currency column are equal to each other. 我只想在货币列中的值彼此相等时才触发小计(109)公式。 Like, count NOT unique values among filtered rows, and if that is equal to 1 fire subtotal(109).
像这样,在已过滤的行之间计算NOT唯一值,如果等于1,则将小计(109)。
Note: I know how to do it with SUMIF by placing a dropdown list with currencies in a separate cell. 注意:我知道如何通过在单独的单元格中放置带有货币的下拉列表来使用SUMIF。 But i want to use filter to do this task.
但我想使用过滤器来执行此任务。
Say we have an autofiltered table like: 假设我们有一个自动过滤的表格,例如:
but we want a warning rather than a SUBTOTAL() if more than one currency has been selected. 但是如果选择了一种以上的货币,我们希望发出警告而不是SUBTOTAL() 。
We need to detect more than one currency. 我们需要检测多种货币。
First enter the following U ser D efined F unction in a standard module: 首先输入以下üSER d标准模块中efined˚F油膏:
Option Explicit
Public Function CountVisibleUnique(rng As Range) As Long
Dim c As Collection, r As Range
Set c = New Collection
On Error Resume Next
For Each r In rng
If r.EntireRow.Hidden = False Then
c.Add r.Text, CStr(r.Text)
End If
Next r
On Error GoTo 0
CountVisibleUnique = c.Count
End Function
Then in cell B8 , replace: 然后在单元格B8中 ,替换:
=SUBTOTAL(109,B2:B6)
with: 有:
=IF(countvisibleunique(C2:C6)>1,"multiple currencies",SUBTOTAL(109,B2:B6))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.