简体   繁体   English

Excel公式可识别列中的最新非空白单元格

[英]Excel formula to identify the most recent non blank cell in a column

I have an extract from an electronic health record for an appointment schedule, that although it is readable in Excel, the data is not sortable or interpretable in an easy manner. 我有一份约会计划电子健康记录的摘录,尽管该记录可以在Excel中读取,但无法轻松地对数据进行排序或解释。 I have successfully gathered much of the data into one field which is separated by commas (which will I will then use text to columns to separate). 我已经成功地将许多数据收集到一个用逗号分隔的字段中(然后我将使用文本对各列进行分隔)。 I now have the info in two separate columns. 我现在在两个单独的列中有信息。 Column A - provider name and date of service Column B - all other necessary info A列-提供商名称和服务日期B列-所有其他必要信息

The problem - column a and column b do not match. 问题-列a和列b不匹配。 For example A2 has the provider name and date of service, but the corresponding additional details come on b8. 例如,A2具有提供者名称和服务日期,但是相应的其他详细信息位于b8上。 There is also not always a one to one match (there are fewer entries in column A than B. 也不总是一对一的匹配(A列中的条目少于B列。

What I want - I need to link (in the above example) A2 to B8 and so forth throughout the columns. 我想要的-在以上各列中,我需要将A2链接到B8(在上面的示例中)。 In the case where there are multiple entries in column b for each in a, I would always want the most recent non blank value in column b to match to B 如果在b列中每个a中有多个条目,我总是希望b列中的最新非空白值与B匹配

I have tried index, lookup, match and nothing are working properly. 我已经尝试过索引,查找,匹配,但没有任何工作正常。 Any assistance in pointing me in the right direction would be helpful. 向我指出正确方向的任何帮助都会有所帮助。

Assuming that the data in Columns A and B come in the same order (meaning that the Nth entry in Column A is the Nth entry in Column B, spaces notwithstanding), and that cells B2 to B7 are blank, it just sounds to me like you need to delete blank cells. 假设A和B列中的数据以相同的顺序排列(意味着A列中的第N个条目是B列中的第N个条目,尽管有空格),并且单元格B2到B7为空,这听起来像是我您需要删除空白单元格。

IMPORTANT: before doing anything, make sure you are working from a copy of your data. 重要提示:在执行任何操作之前,请确保您正在使用数据副本进行操作。 I don't want to be responsible for you losing anything permanently... 我不想对您永久丢失任何东西负责...

Try selecting your entire dataset (everything in Columns A & B) and going to Find&Select>Goto Special (Alt+H,FD,S) in Excel 2016. Probably something similar in earlier versions. 尝试选择整个数据集(A和B列中的所有内容),然后在Excel 2016中转到“查找和选择”>“转到特殊项”(Alt + H,FD,S)。在早期版本中可能类似。

In that screen there is an option to select blanks. 在该屏幕中,有一个选项可以选择空白。 Do that, then back on your worksheet simply delete the selected cells (ctrl + -) and tell Excel to shift the remaining cells UP. 这样做,然后回到工作表中,只需删除选定的单元格(ctrl +-),然后告诉Excel将剩余的单元格上移。 Your corresponding data in columns A & B should now be aligned on the same rows, right? 您现在在A和B列中对应的数据应该在同一行上对齐,对吗?

Based on your description and assuming you data is layed out as: 根据您的描述并假设您的数据布局为:

    (A)      |    (B)
(1)          |
(2) AAA 111  |
(3)          |
(6)          |  Something
(7) BBB 222  |
(8)          |
(11)         |  Something more
(12) CCC 333 |
(13)         |
(16)         |  Something Else

Please note jumps in row numbers 请注意行号跳

In C2 use the following: 在C2中,使用以下命令:

=OFFSET($A$2,(ROW(A2)-2)*5,0,1,1)

and in D2 use the following 在D2中使用以下命令

=OFFSET($A$2,(ROW(A2)-2)*5+4,1,1,1)

now to deal with 0 showing up when the entry is blank you could wrap the offset function in an if statement 现在要处理当条目为空白时显示的0,您可以将偏移量函数包装在if语句中

=if(OFFSET($A$2,(ROW(A2)-2)*5+4,1,1,1)=0,"",OFFSET($A$2,(ROW(A2)-2)*5+4,1,1,1))

Assuming there is at least 1 entry in column A which belongs to column B you can use this to have a non-volatile function: 假设A列中至少有1个条目属于B列,则可以使用它来具有非易失性功能:

D1: {=IFERROR(INDEX(A:A,MATCH(SMALL(IF(B$1:INDEX(B:B,MATCH("zzz",B:B))<>"",ROW(B$1:INDEX(B:B,MATCH("zzz",B:B)))),ROW()),IF(A$1:INDEX(A:A,MATCH("zzz",A:A))<>"",ROW(A$1:INDEX(A:A,MATCH("zzz",A:A)))),1)),"")}
E1: {=IFERROR(INDEX(B:B,SMALL(IF(B$1:INDEX(B:B,MATCH("zzz",B:B))<>"",ROW(B$1:INDEX(B:B,MATCH("zzz",B:B)))),ROW())),"")}

And to not get the entry of column a multiple times, just use for D2: 为了避免多次获取列的条目,只需将其用于D2:

D2: {=IFERROR(IF(INDEX(A:A,MATCH(SMALL(IF(B$1:INDEX(B:B,MATCH("zzz",B:B))<>"",ROW(B$1:INDEX(B:B,MATCH("zzz",B:B)))),ROW()),IF(A$1:INDEX(A:A,MATCH("zzz",A:A))<>"",ROW(A$1:INDEX(A:A,MATCH("zzz",A:A)))),1))=INDEX(A:A,MATCH(SMALL(IF(B$1:INDEX(B:B,MATCH("zzz",B:B))<>"",ROW(B$1:INDEX(B:B,MATCH("zzz",B:B)))),ROW()-1),IF(A$1:INDEX(A:A,MATCH("zzz",A:A))<>"",ROW(A$1:INDEX(A:A,MATCH("zzz",A:A)))),1)),"",INDEX(A:A,MATCH(SMALL(IF(B$1:INDEX(B:B,MATCH("zzz",B:B))<>"",ROW(B$1:INDEX(B:B,MATCH("zzz",B:B)))),ROW()),IF(A$1:INDEX(A:A,MATCH("zzz",A:A))<>"",ROW(A$1:INDEX(A:A,MATCH("zzz",A:A)))),1))),"")}

But as said: If a value in column A does not have any value in column B, then it will be skipped! 但是请注意:如果A列中的值在B列中没有任何值,那么它将被跳过!

This are all array formulas and will be entered without the {} but must to be confirmed with Strl + Shift + Enter ! 这些都是数组公式,将不带{}输入,但必须通过Strl + Shift + Enter确认

在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM