excel - 行与列的比较(命名范围)
问题描述
我的数据:
表格1 | 人1 | 人2 | 人3 | 人4 | 人5 | 人6 | 人7 | 人8 |
---|---|---|---|---|---|---|---|---|
周一 | 一种 | 乙 | C | D | 乙 | 乙 | F | F |
周二 | 乙 | F | D | C | 乙 | 乙 | F | 一种 |
周三 | C | D | 一种 | F | 乙 | 乙 | F | F |
地方 |
---|
一种 |
乙 |
C |
D |
我的问题:
我想比较是否在每一天命名范围Place
中的所有值都在行内Monday, Tuesday, Wednesday,...
,如果有些缺少这些是哪一个。
所以,因为Wednesday
它应该给出一个"B" missing
公式IF
或任何你有的建议。"E"
并且"F"
不在Place
,那些应该被忽略。
到目前为止我尝试了什么:
研究总是让我比较 2 列而不是行和列。
我试过这样的数组函数($B3:$I3 == "Monday row" == "row1"):
=INDEX(Place;SMALL(IF(ISERROR(MATCH(Place;$B3:$I3;0));(ROW(Place)-MIN(ROW(Place))+1);"");ROWS($A$1:A1)))
错误:比较单个行需要许多“帮助”列。还有“#NUM!” 即使所有值都
Place
发生或仅缺少一个值。
我开始使用许多COUNTIF
公式,例如
=COUNTIF(row1;INDEX(Place;1))+COUNTIF(row1;INDEX(Place;2))+COUNTIF(row1;INDEX(Place;3))+COUNTIF(row1;INDEX(Place;4))
当所有值都出现时给我一个"4"
,如果部分或全部丢失,则给我一个较低的值。但是我如何才能将这些数字与“看到”哪些值丢失导致“低于 4”数字联系起来呢?
解决方案
我认为这个 UDF 会给你你想要的结果。
Function Check(Data As Range) As String
' 296
' Data specifies one row from the table excl column #1
Dim Fun() As String ' function return value
Dim i As Long ' index to Fun()
Dim Places As Variant ' array of range "Place"
Dim R As Long ' loop counter; Places
Dim Match As Variant ' result of Match() function
' this command will slow down your workbook.
' If inconvenient (too sluggish), remove it.
' If removed, the UDFs in the worksheet may not recalculate as you expect.
' Click "Calculate Now" on the ribbon's 'Formulas' tab to update.
Application.Volatile
' the named range "Places" must exist in the worksheet
' in the sample it's B10:B13
Places = ActiveSheet.Range("Places").Value
ReDim Fun(UBound(Places))
For R = 1 To UBound(Places)
Match = Application.Match(Places(R, 1), Data, 0)
If IsError(Match) Then
i = i + 1
Fun(i) = Places(R, 1)
End If
Next R
If i Then
Fun(0) = "Missing: "
Else
Fun(0) = "All present"
End If
ReDim Preserve Fun(i)
Check = Replace(Join(Fun, ", "), ",", vbNullString, 1, 1)
End Function
代码必须粘贴到标准代码模块。您必须插入它,默认情况下它的名称类似于“Module1”,您可以更改它。不要使用任何现有的代码模块。通过输入类似于以下的语法,从工作簿中的任何位置调用该函数:=Check(C3:J3)
. 这里 C3:J3 定义了表的倒数第二列,不包括“星期一”,结果将根据 range 评估此 range 中列出的项目Places
。
推荐阅读
- excel - 在 VBA 中引用没有固定地址的新列
- antlr4 - 优先与可选就足够了
- javascript - 反应 useEffect 挂钩引用不正确的值
- java - 程序的 Java 阶乘计算不能做 0,1,2 我该如何解决这个问题
- javascript - 在 React 中将 props 传递给 this.props.children
- vue.js - vue/element ui 表单验证
- amazon-web-services - 使用 Azure AD 联合 SSO 访问 AWS 的桌面应用程序
- amazon-cloudformation - 这可能有可选的 SSM 参数吗?
- java - 如何使用版本 2 的 spring boot admin 和版本 1.5 的 spring boot?
- ios - Nativescript:添加运行脚本阶段