简体   繁体   English

在 MS Excel 中查找前一个单元格,该单元格是列中的数字

[英]In MS Excel look for the previous cell that is a number in a column

For the same company (in this case Company A), I want to change the "NA" to the last available number.对于同一家公司(在本例中为公司 A),我想将“NA”更改为最后一个可用的号码。 For example, cell D3 and D4 are NA, so I want it both change to last available number (which is "1" in cell D2).例如,单元格 D3 和 D4 是 NA,所以我希望它都更改为最后一个可用数字(在单元格 D2 中为“1”)。 If they are different company (like cell B7 and B6), then return the original "NA".如果他们是不同的公司(如单元格 B7 和 B6),则返回原始的“NA”。

I tired =IF(C3= "NA", INDEX(C$2:C$11,MATCH(TRUE,ISNUMBER(C$2:C$11),0),1),C3) , but it does not work as it returns #N/A.我厌倦了=IF(C3= "NA", INDEX(C$2:C$11,MATCH(TRUE,ISNUMBER(C$2:C$11),0),1),C3) ,但它不起作用,因为它返回 #不适用。 Please can anyone help?请问有人可以帮忙吗? Thanks!谢谢!

Image图片在此处输入图像描述

It seems to work for me though?它似乎对我有用? Recreated the data for company A and replaced "," for ";"为 A 公司重新创建了数据,并将“,”替换为“;” as it is the separator I use.因为它是我使用的分隔符。 Additionally I removed the spaces in the formula as I never use them in Excel.此外,我删除了公式中的空格,因为我从未在 Excel 中使用它们。

As a result the formula gives the wanted result.结果,公式给出了想要的结果。

Does your Excel support the formulas you are trying to use?您的 Excel 是否支持您尝试使用的公式?

在此处输入图像描述

The column codes of your verbal description do not match the column codes of your screenshot.您的口头描述的列代码与屏幕截图的列代码不匹配。 So just to be clear, in the following answer I will refer to the column codes as given in your screenshot.所以为了清楚起见,在下面的答案中,我将参考屏幕截图中给出的列代码。

The formula that you included does compute the result for me, by the way it is set up, it does not calculate what you described verbally.您包含的公式确实为我计算了结果,通过它的设置方式,它不会计算您口头描述的内容。

In its form as written in your question, the formula ignores the company name and when faced with an 'NA' value, it returns the first number it finds starting from the top .在您的问题中所写的形式中,该公式忽略了公司名称,当遇到“NA”值时,它会返回从 top 开始找到第一个数字。

If I understand correctly, you want the formula to only take into consideration numbers associated with the same company name in column A, and when faced with 'NA', return the "most recent" number it finds for that company starting from the current row going up (given that date values are in order).如果我理解正确,您希望公式仅考虑与 A 列中相同公司名称关联的数字,并且在遇到“NA”时,返回从当前行开始为该公司找到的“最新”数字上升(假设日期值是有序的)。

The following formula incorporates those features when pasted into cell D2:以下公式在粘贴到单元格 D2 时包含这些功能:

=IFERROR(INDEX(FILTER($C$2:$C2,($A$2:$A2=$A2)*(ISNUMBER($C$2:$C2))),SUM(($A$2:$A2=$A2)*(ISNUMBER($C$2:$C2)))),"NA")

With this solution, the company names do not have to be in order, yet the date values do.使用此解决方案,公司名称不必按顺序排列,但日期值却可以。 The formula can be adjusted for cases where neither company names, nor date values are in order.对于公司名称和日期值都不按顺序排列的情况,可以调整公式。

Note that the FILTER function is only available in Excel for Microsoft 365 and Excel 2021. In Excel 2019, Excel 2016 and earlier versions, it is not supported. Note that the FILTER function is only available in Excel for Microsoft 365 and Excel 2021. In Excel 2019, Excel 2016 and earlier versions, it is not supported.

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

相关问题 MS Excel:计算一列中与其左侧的单元格编号相同的单元格的数量 - MS Excel: Count the number of cells in a column that have the same number as the cell to the left of it 在列中查找数字,然后在结果单元格中放置1或0 - Look for a number in a column and place a 1 or 0 in the result cell 告诉 excel 查看当前 I 数组的前一个单元格 - Tell excel to look at previous cell to current I array MS Excel 2010 中的最后一行和列号 - Last row and column number in MS Excel 2010 Excel 2010 VBA:设置上一列中单元格引用单元格的颜色 - Excel 2010 VBA: Set the color of a cell reference cell in previous column 如果列中的前一个单元格为空,则DataReader不会在Excel单元格中查看数据 - DataReader does not see data in Excel cell if previous cell in the column are empty 需要遍历 AI 列,如果单元格不为空,则查看 W 列并在下一列中移动数字 - Need to loop through column AI and if cell is not empty then look look in column W and move number in next column 修改一个Excel宏以查看整个列而不是单个单元格 - Modify an excel macro to look at whole column instead of single cell MS Excel 2013 datagridview外观 - MS Excel 2013 datagridview look Excel-对列求和,直到到达非数字的单元格 - Excel - Sum column until it reaches a cell that is not a number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM