简体   繁体   English

MS Excel:如果查找数组太大,“ MATCH()”将找不到包含文本的单元格

[英]MS Excel: “MATCH()” does not find cells containing text if lookup array is too large

I am creating a large and complicated schedule, and I want one view which shows the schedule as a day-time grid, and another which allows one to look up a speaker by name from an alphabetical list. 我正在创建一个庞大而复杂的日程表,我想要一个视图,该视图将日程表显示为日间网格,而另一个视图则允许该视图从字母列表中按名称查找发言人。 I have posted a simplified example here: 我在这里发布了一个简化的示例:

http://www.calpoly.edu/~epearse/excel-issue.png

In the alphabetical list, the day and time should be populated by a function using MATCH. 在字母列表中,日期和时间应由使用MATCH的函数填充。 Just as an example, I manually typed what I would like to have happen for Jones. 举个例子,我手动输入了Jones希望发生的情况。

I cannot get MATCH() to locate the speaker's name in the timetable correctly. 我无法通过MATCH()在时间表中正确找到发言人的姓名。 There are no hidden characters: notice that in cell D15, Excel correctly recognizes that G2 and C7 are identical. 没有隐藏的字符:请注意,在单元格D15中,Excel正确识别出G2和C7相同。

Here is what happens if I put various code in H2: 如果我将各种代码放入H2,会发生以下情况:

  • =MATCH(G2,$A$1:$D$9) results in #N/A = MATCH(G2,$ A $ 1:$ D $ 9)结果为#N / A
  • =MATCH(G2,$C$2:$C$9) results in #N/A = MATCH(G2,$ C $ 2:$ C $ 9)结果为#N / A
  • =MATCH(G2,$B$7:$D$7) results in 2 (correctly!) = MATCH(G2,$ B $ 7:$ D $ 7)结果为2(正确!)
  • =MATCH(G2,$A$7:$D$7) results in #N/A = MATCH(G2,$ A $ 7:$ D $ 7)结果为#N / A

What I would like is to put =MATCH(G2,$A$1:$D$9) into H2 and then fill cells down to H25, and have Excel indicate the column number of the day in which the adjacent name appears, then use INDIRECT or something to convert this number into the day of the week. 我想要将= MATCH(G2,$ A $ 1:$ D $ 9)放入H2,然后将单元格填充到H25,并让Excel指出出现相邻名称的日期的列号,然后使用INDIRECT或将其转换为星期几的方法。

It may be that including column A in the search array causes problems because of the different data types. 由于数据类型不同,在搜索数组中包含列A可能会导致问题。 As an experiment, I made the first column into TEXT, and in this case =MATCH(G2,$A$7:$D$7) incorrectly returns 1! 作为实验,我将第一列放入TEXT,在这种情况下= MATCH(G2,$ A $ 7:$ D $ 7)错误地返回1!

And even so, I cannot understand why $B$7:$D$7 works but neither $C$2:$C$9 nor $B$7:$D$8 will. 即使这样,我也无法理解为什么$ B $ 7:$ D $ 7起作用,但是$ C $ 2:$ C $ 9或$ B $ 7:$ D $ 8都不起作用。

Any workarounds or alternative strategies would be greatly appreciated, thanks. 任何解决方法或替代策略,将不胜感激,谢谢。

To do this you need to add in some other logic to find the correct column and row. 为此,您需要添加其他逻辑以找到正确的列和行。 This AGGREGATE() Function does the job. 此AGGREGATE()函数完成此工作。

For Day use: 日间使用:

=INDEX($A$1:$D$1,AGGREGATE(15,6,COLUMN($A$2:$D$9)/(($A$2:$D$9=G2)),1))

For Hour: 每小时:

=INDEX($A$1:$A$9,AGGREGATE(15,6,ROW($B$1:$D$9)/(($B$1:$D$9=G2)),1))

在此处输入图片说明

The AGGREGATE() Function was introduced in Excel 2010. Excel 2010中引入了AGGREGATE()函数。


For other Versions: 对于其他版本:

Pre 2010, they will need to be Array Formulas: 在2010年之前,它们将需要是数组公式:

Day: 天:

=INDEX($A$1:$D$1,MIN(IF($A$2:$D$9=G2,COLUMN($A$2:$D$9))))

Hour: 小时:

=INDEX($A$1:$A$9,MIN(IF($B$1:$D$9=G2,ROW($B$1:$D$9))))

Being an Array Formula it must be confirmed with Ctrl-Shift-Enter when exiting Edit mode. 作为数组公式,退出编辑模式时必须通过Ctrl-Shift-Enter确认。 When done correctly Excel will automatically put {} around the formula to denote an array formula. 正确完成后,Excel会自动在公式周围放置{}来表示数组公式。

Newest Office 360 or online: 最新的Office 360​​或在线:

Day: 天:

=INDEX($A$1:$D$1,MINIFS(COLUMN($A$2:$D$9),$A$2:$D$9,G2))

Hour: 小时:

=INDEX($A$1:$A$9,MINIFS(ROW($B$1:$D$9),$B$1:$D$9,G2))

As to the reason MATCH will not work in this case: 至于MATCH在这种情况下将无法工作的原因:

MATCH() only works with a single row or column and not a multiple column/row range. MATCH()仅适用于单行或单列,而不适用于多列/行范围。 It is set up to return a number equal to the order place found and therefore must be a 1 dimensional array. 它设置为返回等于找到的顺序的数字,因此必须是一维数组。

The most efficient way to do this given your dataset is to use three MATCH queries - one for each column. 在给定数据集的情况下,最有效的方法是使用三个MATCH查询-每列一个。

For the Day, that looks like this: 对于Day,它看起来像这样:

=IF(ISERROR(MATCH(G2,$B$2:$B$10,0)),"",$B$1)&IF(ISERROR(MATCH(G2,$C$2:$C$10,0)),"",$C$1)&IF(ISERROR(MATCH(G2,$D$2:$D$10,0)),"",$D$1)

For the Time, that looks like this: 对于“时间”,它看起来像这样:

=INDEX($A$2:$A$10,IFERROR(MATCH(G2,$B$2:$B$10,0),0) + IFERROR(MATCH(G2,$C$2:$C$10,0),0) + IFERROR(MATCH(G2,$D$2:$D$10,0),0))

...but truth be told, on small datasets such as this one, you won't notice any performance difference on this approach vs Scott's AGGREGATE approach. ...但是说实话,在像这样的小型数据集上,与Scott的AGGREGATE方法相比,您不会注意到此方法的任何性能差异。 On large datasets (thousands of rows) you probably will. 在大型数据集(数千行)上,您可能会这样做。

Note that another reason your initial approach failed is that you did not specify the 3rd argument of MATCH, and so Excel used the default value that assumes your list data is sorted alphabetically. 请注意,您的初始方法失败的另一个原因是您没有指定MATCH的第3个参数,因此Excel使用了默认值,该默认值假定您的列表数据按字母顺序排序。 You almost never want to omit that argument, and you almost always want to use FALSE (or Zero, which means FALSE to Excel) 您几乎永远不想忽略该参数,并且几乎总是想要使用FALSE(或零,这意味着从FALSE到Excel)

Alternative solution with vba & listobjects (you need to give the two tables the names as appear in the code below) sheet screenshot Public Sub makeAppointmentList() Dim aSheet As Worksheet Set aSheet = ThisWorkbook.Worksheets("sheet1") vba和listobjects的替代解决方案(您需要给两个表命名,如下面的代码所示)工作表屏幕快照 Public Sub makeAppointmentList()Dim aSheet As Worksheet Set aSheet = ThisWorkbook.Worksheets(“ sheet1”)

Dim aSchedule As ListObject
Set aSchedule = aSheet.ListObjects("schedule")

Dim anAppointmentList As ListObject
Set anAppointmentList = aSheet.ListObjects("appointmentList")

On Error Resume Next
anAppointmentList.DataBodyRange.Delete
On Error GoTo 0

Dim c As ListColumn
Dim r As ListRow
Dim newRow As ListRow

For Each c In aSchedule.ListColumns
    For Each r In aSchedule.ListRows
        If c.Index > 1 And Intersect(c.Range, r.Range) <> "" Then
            Set newRow = anAppointmentList.ListRows.Add
            Intersect(newRow.Range, anAppointmentList.ListColumns("Name").Range).Value = Intersect(c.Range, r.Range)
            Intersect(newRow.Range, anAppointmentList.ListColumns("Day").Range).Value = Intersect(c.Range, aSchedule.HeaderRowRange)
            Intersect(newRow.Range, anAppointmentList.ListColumns("Time").Range).Value = Intersect(aSchedule.ListColumns(1).Range, r.Range)
        End If
    Next r
Next c
anAppointmentList.Sort.SortFields.Clear
anAppointmentList.Sort.SortFields.Add Key:=Intersect(anAppointmentList.HeaderRowRange, _
                                                      anAppointmentList.ListColumns("Name").Range)
anAppointmentList.Sort.SortFields.Add Key:=Intersect(anAppointmentList.HeaderRowRange, _
                                                      anAppointmentList.ListColumns("Day").Range), _
                                      CustomOrder:="Mon,Tue,Wed,Thu,Fri,Sat,Sun"
anAppointmentList.Sort.SortFields.Add Key:=Intersect(anAppointmentList.HeaderRowRange, _
                                                      anAppointmentList.ListColumns("Time").Range)
anAppointmentList.Sort.Apply
Dim s As SortField
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel Match Multiple Criteria Lookup Array:从列表中查找包含所有值的列,并返回数组中的列 position - Excel Match Multiple Criteria Lookup Array: Find columns that contains all values from a list and return the columns position in the array string []。即使文本在数组中,也无法找到匹配项 - string[].Contains does not find a match even if the text is in the array 包含 integer '0' 的 PowerShell 数组与“^(0|3010)$”不匹配 - PowerShell array containing integer '0' does not match “^(0|3010)$” Excel数组公式,仅复制包含字符串的单元格 - Excel array Formula that copies only cells containing a string 在公式中使用索引、匹配和行/列 excel 函数返回一个子集数组,其中仅包含带文本的单元格并排除空单元格 - Use index, match, and row/column excel functions in a formula to return a subset array with just cells with text and exclude the empty ones Excel数组查找公式 - Excel Array Lookup Formula Excel 查找/数组 - Excel lookup / array 在Excel中搜索单元格数组 - Searching an Array of Cells in Excel 单元格作为数组Excel - Cells as array Excel 使用与MATCH()Excel函数中的“ lookup_value”具有相同含义的字符串数组 - Using an array of strings that have the same meaning as a “lookup_value” in the MATCH() excel function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM