简体   繁体   English

检查excel列值是否彼此相等

[英]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.

相关问题 如果其他列值匹配,VBA 将列设置为彼此相等 - VBA Set Columns equal to each other if other column values match 根据其他两个相等的列更新excel列中的值 - updating values in excel column depending on two other columns being equal CSV文件中A列中的一些相等值,并且需要从与excel中该列匹配的其他文件中复制值 - Some equal values in column A from a CSV file and need to copy values from other files that matches with that column in excel 在Excel中,我有两列等于第三列,但它们彼此不相等。 如何使他们彼此平等? - In Excel I have two columns that equal a third column but they don't equal each other. How do I get them to equal each other? 从一个excel表的列中的单元格中获取值,并检查该值是否存在于其他excel表的列中 - Take values from cells in column of one excel table and check if this values exist in column of other excel table 循环浏览一个excel列,并检查每个值是否与另一个excel匹配 - Loop Through an excel column and check if each values has a match on another excel 擅长将一列包含多个单词重复项,将另一列包含值(数字),并需要用公式将每个单词的所有值求和 - excel one column with many word duplicates and the other with values (number) and need to sum all values for each word with formula 如果3个列值小于或等于3个其他值,则获取行号 - Get row number if 3 column values are below or equal to 3 other values Excel条件格式,如果A列中的2个值相等,但B列中的相应值不相等 - Excel Conditional Formatting if 2 values in column A are equal, but their corresponding values in column B do not equal 如何检查单元格值是否彼此平衡 - How to check if Cell values balance each other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM