查找包含数字的行中的第一个单元格?

发布于 2024-10-08 12:56:13 字数 1282 浏览 6 评论 0原文

我正在 Excel 中使用导出的表格,如下所示:

|-------------------------------------------------------------------------------|
|   |        A          |  B  |  C  |  D  |  E  |  F  |   G   |  H  |     I     |
|---|-------------------|-----|-----|-----|-----|-----|-------|-----|-----------|
| 1 |      Domain       | JAN | FEB | MAR | APR | MAY | Start | End |   Change  |
|---|-------------------|-----|-----|-----|-----|-----|-------|-----|-----------|
| 2 | www.mydomain1.com |     |   1 |   4 |   3 |   1 |     1 |   1 |         0 |
|---|-------------------|-----|-----|-----|-----|-----|-------|-----|-----------|
| 3 | www.mydomain2.com |   2 |   4 |  12 |  18 |  23 |     2 |  23 |        21 |
|---|-------------------|-----|-----|-----|-----|-----|-------|-----|-----------|
| 4 | www.mydomain3.com |     |     |  14 |  12 |     |    14 | xxx | NOT FOUND |
|-------------------------------------------------------------------------------|

我正在尝试将当前状态(最后一个单元格)与原始单元格(第一个带有值的单元格)进行比较。

在 I 列中,我有公式 =IF(G2 = "xxx", "NOT FOUND", IF(H2 = "xxx", "NOT FOUND", H2 - G2))

在 H 列中,我有公式 =IF(F2 = "", "xxx", F2)

在 G 列中,我需要找到第一个带有数字的单元格。如果该范围内没有,我需要 G 为“xxx”。我想我只需要检查范围(B2 到 F2)中包含值的第一个单元格,而不仅仅是数字。我尝试使用索引和匹配组合,但我不太理解它。

I'm working in Excel with an exported table such as this:

|-------------------------------------------------------------------------------|
|   |        A          |  B  |  C  |  D  |  E  |  F  |   G   |  H  |     I     |
|---|-------------------|-----|-----|-----|-----|-----|-------|-----|-----------|
| 1 |      Domain       | JAN | FEB | MAR | APR | MAY | Start | End |   Change  |
|---|-------------------|-----|-----|-----|-----|-----|-------|-----|-----------|
| 2 | www.mydomain1.com |     |   1 |   4 |   3 |   1 |     1 |   1 |         0 |
|---|-------------------|-----|-----|-----|-----|-----|-------|-----|-----------|
| 3 | www.mydomain2.com |   2 |   4 |  12 |  18 |  23 |     2 |  23 |        21 |
|---|-------------------|-----|-----|-----|-----|-----|-------|-----|-----------|
| 4 | www.mydomain3.com |     |     |  14 |  12 |     |    14 | xxx | NOT FOUND |
|-------------------------------------------------------------------------------|

I'm trying to compare the current state (last cell) to the original cell (first cell with a value).

In column I, I have the formula =IF(G2 = "xxx", "NOT FOUND", IF(H2 = "xxx", "NOT FOUND", H2 - G2))

In column H, I have the formula =IF(F2 = "", "xxx", F2)

In column G, I need to find the first cell with a number. If there isn't one in that range, I need G to be "xxx". I suppose I only need to check for the first cell in the range (B2 to F2) that contains a value, not just a number. I tried using an Index and Match combo, but I couldn't quite understand it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦行七里 2024-10-15 12:56:13

以下公式(在 $G$2 中并填写)应该可以解决问题:

=IF(ISBLANK(F2),"xxx",INDEX(B2:E2,,COUNTBLANK(B2:F2)+1))

请注意,只有在第一个条目和最后一个条目之间没有其他空白单元格时,这才有效。

更新:这是一个更通用的选项来自 Mr.Excel 论坛

=INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0))

此公式必须作为“数组公式”输入,这意味着粘贴公式后必须按 CTRL-SHIFT-ENTER。

对评论的回复:

它工作得很好,除了如果一行中所有单元格都是空的,它会返回#N/A。因此,我稍微更改了公式以包含 IsNA() 条件:

=IF(ISNA(INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0))), "xxx",
    INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0)))

您可以执行以下操作,而不是重复整个公式:

=IF(COUNTBLANK(B2:F2)=COLUMNS(B2:F2),"xxx",
    INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0)))

The following formula (in $G$2 and filled down) should do the trick:

=IF(ISBLANK(F2),"xxx",INDEX(B2:E2,,COUNTBLANK(B2:F2)+1))

Note that this will only work if there are no other blank cells in between the first and last entries.

update: Here is a more versatile option from the Mr.Excel forum:

=INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0))

This one has to be entered as an "array formula" which means you must press CTRL-SHIFT-ENTER after pasting in the formula.

response to comment:

It works great, except that if all cells are empty on a row, it returns #N/A. So, I changed the formula slightly to include an IsNA() condition:

=IF(ISNA(INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0))), "xxx",
    INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0)))

Rather than duplicate the whole formula, you could do the following:

=IF(COUNTBLANK(B2:F2)=COLUMNS(B2:F2),"xxx",
    INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0)))
清泪尽 2024-10-15 12:56:13

如果作为 ARRAY 公式输入(ctrl-shift-enter),则以下内容有效。

如果中间有空白单元格也适用。

{=INDEX(B2:F2,1,MIN(IF(ISBLANK(B2:F2),99999,COLUMN(B2:F2))))}

HTH

编辑

这也控制错误:

{=IF(ISERROR(INDEX(B2:F2,1,MIN(IF(ISBLANK(B2:F2),9999,COLUMN(B2:F2))))),"xxx",
  INDEX(B2:F2,1,MIN(IF(ISBLANK(B2:F2),9999,COLUMN(B2:F2)))))}

The following works if entered as an ARRAY formula (ctrl-shift-enter).

Works also if there are blank cells in the middle.

{=INDEX(B2:F2,1,MIN(IF(ISBLANK(B2:F2),99999,COLUMN(B2:F2))))}

HTH

Edit

This one controls the error too:

{=IF(ISERROR(INDEX(B2:F2,1,MIN(IF(ISBLANK(B2:F2),9999,COLUMN(B2:F2))))),"xxx",
  INDEX(B2:F2,1,MIN(IF(ISBLANK(B2:F2),9999,COLUMN(B2:F2)))))}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文