简体   繁体   English

根据Excel中第一列的变量查找行的最后一个值

[英]Finding last value of row depending on the first column's variable in Excel

I'm currently trying to find a formula that will give me the last value of the row Total assets (94054000000) corresponding to the T1 2022. My main problem stems from the fact that I'm trying to automate this process and I don't want the formula to be based on the column's heading "T1 2022".我目前正在尝试找到一个公式,该公式将为我提供与 T1 2022 相对应的总资产 (94054000000) 行的最后一个值。我的主要问题源于我试图自动化这个过程而我没有'不希望公式基于列标题“T1 2022”。

Is there a function that can just search through an array, find "total assets" as the value of the first column and give me the last value of the corresponding row ?有没有一个函数可以只搜索一个数组,找到“总资产”作为第一列的值,然后给我相应行的最后一个值? Maybe this can be done through Vlookup , but I have not been able to find a way to accomplish what I want to do so far.也许这可以通过 Vlookup 来完成,但到目前为止我还没有找到一种方法来完成我想做的事情。

The two formulas that I've been using to try and extract the data have been.我一直用来尝试提取数据的两个公式是。

=VLOOKUP("Total Assets",'10k B'!$A$2:$L$67,MATCH("T1 2022",'10k B'!$A$1:$L$1,0),0)

Is there a way to get the last value of the Total assets row without specifying that I want the column value to be T1 2022 ?有没有办法在不指定我希望列值为 T1 2022 的情况下获取 Total assets 行的最后一个值? The Total Assets row also move from one company to another, hence why I'd prefer a formula that can search through an array rather than just plainly doing something like总资产行也从一家公司转移到另一家公司,因此我更喜欢一个可以搜索数组的公式,而不是简单地做类似的事情

=LOOKUP(2,2/(2:2<>""),2:2)

在此处输入图像描述

Thank you in advance !先感谢您 !

There are many ways.有很多方法。 Different limitatiomns with each .每个都有不同的限制。 So, wanted to try my own, make it sure.所以,想尝试我自己的,确保它。

Ok, a very simple, basic, low level of excel knowledge level, but it works for excel 2019+好的,很简单,基础,excel知识水平低的一个,但是对excel 2019+有效

4 ways (at least): 4种方式(至少):

1. 1.

So since all known methods (below and many more) to do it, have their small print expetions (Ie "won't give correct result if empty cells in range", "doesn't work if duplicates in row", and , "doest work when last cell is 0" - So you'd need accounting for - I have wanted to and decided to make a non-vba old fashioned Excel formula which will work to always give the last cell column number regardless. Here it is -因此,由于所有已知的方法(以下以及更多)都可以做到这一点,因此请使用它们的小字体(即“如果范围内的单元格为空,则不会给出正确的结果”,“如果在行中重复则不起作用”,以及,“当最后一个单元格为 0 时不起作用” - 所以你需要考虑 - 我想要并决定制作一个非 vba 老式 Excel 公式,该公式将始终给出最后一个单元格的列号。这是 -

This approach assumes nothing.这种方法没有任何假设。 Doesn't need non-blank cells.不需要非空白单元格。 (Ie works with even with blanks in your rows/ranges. Work even with duplicates & works even with 0 as last cell),Doesnt fail with 0's or empty cells, and gives you the position of last used cell in range/row without you having to know anything about your data, or the last cell value, whatever value it that is. (即,即使您的行/范围中有空白也可以使用。即使有重复项,也可以使用 0 作为最后一个单元格),不会因 0 或空单元格而失败,并在没有您的情况下为您提供范围/行中最后使用的单元格的位置必须知道有关您的数据或最后一个单元格值的任何信息,无论它是什么值。 Treats cells as blocks to work through & count from left to the last filled/last used cell .将单元格视为块来处理并从左到最后填充/最后使用的单元格计数。

[Depending on your excel version, you might need to split up formula by/into helper cells, or use a made-for-2016-earlier vba udf for the 360 concat function I'm using in here).] [根据您的 excel 版本,您可能需要将公式拆分为辅助单元格,或者使用为 2016 年早期制作的 vba udf 用于我在此处使用的 360 concat 函数。]

Formula to find the position/last used cell in a row (without needing to fill blanks cells, or know its range/size, know if empty or non-empty cells or not, or needing to know anything at all about your data):在一行中查找位置/最后使用的单元格的公式(无需填充空白单元格,或知道其范围/大小,知道是否为空或非空单元格,或者根本不需要了解您的数据):

=IF(AND((LEN(A1))>0,ISERROR(LEN(LEFT(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"|"&"@"&"|",(LEN(CONCAT(1:1&"|"))-LEN(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"")))/LEN("|"&LOOKUP(2,1/(1:1<>""),1:1))),FIND("|"&"@"&"|",SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"|"&"@"&"|",(LEN(CONCAT(1:1&"|"))-LEN(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"")))/LEN("|"&LOOKUP(2,1/(1:1<>""),1:1))),1)))-LEN(SUBSTITUTE(LEFT(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"|"&"@"&"|",(LEN(CONCAT(1:1&"|"))-LEN(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"")))/LEN("|"&LOOKUP(2,1/(1:1<>""),1:1))),FIND("|"&"@"&"|",SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"|"&"@"&"|",(LEN(CONCAT(1:1&"|"))-LEN(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"")))/LEN("|"&LOOKUP(2,1/(1:1<>""),1:1))),1)),"|",""))+1)),1,LEN(LEFT(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"|"&"@"&"|",(LEN(CONCAT(1:1&"|"))-LEN(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"")))/LEN("|"&LOOKUP(2,1/(1:1<>""),1:1))),FIND("|"&"@"&"|",SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"|"&"@"&"|",(LEN(CONCAT(1:1&"|"))-LEN(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"")))/LEN("|"&LOOKUP(2,1/(1:1<>""),1:1))),1)))-LEN(SUBSTITUTE(LEFT(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"|"&"@"&"|",(LEN(CONCAT(1:1&"|"))-LEN(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"")))/LEN("|"&LOOKUP(2,1/(1:1<>""),1:1))),FIND("|"&"@"&"|",SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"|"&"@"&"|",(LEN(CONCAT(1:1&"|"))-LEN(SUBSTITUTE(CONCAT(1:1&"|"),"|"&LOOKUP(2,1/(1:1<>""),1:1),"")))/LEN("|"&LOOKUP(2,1/(1:1<>""),1:1))),1)),"|",""))+1)

paste in a cell you want the output, and it returns the last used column in your range.粘贴到您想要输出的单元格中,它会返回您范围内最后使用的列。

Im sure someone somewhere could make/has a obvious better one, made with lambdas or textjoins i imagine, and im sure it does exists elsewhere (but tried exaustive looking for it and nothing on the web* it seems to not be done anywhere), so but happy ive done this now ( or you could just use vba ).我确定某个地方的某个人可以制作/有一个明显更好的,我想是用 lambdas 或 textjoins 制作的,并且我确定它确实存在于其他地方(但尝试过详尽地寻找它并且在网络上什么都没有*它似乎没有在任何地方完成),所以但很高兴我现在这样做了(或者你可以只使用 vba )。 Relieved I have done this.松了一口气,我已经做到了。

You dont need to know anything about or do anything to your data (the value, the header, whats in your cells or if there are blank cells , unfilled cells in there or not, or whats in them).您不需要了解任何有关数据或对数据执行任何操作(值、标题、单元格中的内容,或者是否有空白单元格、是否存在未填充的单元格,或者其中有什么)。 You don't need to know anything before hand.你不需要事先知道任何事情。 Thats what I made sure of.那是我确定的。 I've always wanted to do this with a only-formula after being told (and working on) the counta / countblank problem in earlier versions of excel.在被告知(并处理)早期版本的 excel 中的 counta / countblank 问题之后,我一直想用一个唯一的公式来做到这一点。

The only thing you need to make sure of is the special characters used to make-it / push it to work, |您唯一需要确定的是用于制作/推动它工作的特殊字符, | and @ , are truelly unique and never present in your data, so perhaps use char(1) and char(200) or something partciular to you, to be sure.@ ,是真正独一无二的,并且永远不会出现在您的数据中,所以可以使用char(1)char(200)或对您来说特别的东西,可以肯定的是。

There is also this,还有这个,

2. 2.

Index Match last value in range索引匹配范围内的最后一个值

But doesnt work when/if last value is duplicated.但是当/如果最后一个值重复时不起作用。

=COLUMN(INDEX(1:1,MATCH(2,1/(1:1=LOOKUP(2,1/(1:1<>""),1:1)))))

This works well so for me too:这对我也很有效:

see this Display the column number of the last non-empty cell within a range (if values are not unique)看到这个显示范围内最后一个非空单元格的列号(如果值不唯一)

=AGGREGATE(14,7,(COLUMN(1:1)-MIN(COLUMN(1:1))+1)/(1:1>0),1)

But 'fails' if last value is 0 or 0's after yourdata (depending which way you see it)但是如果你的数据之后的最后一个值为 0 或 0,则“失败”(取决于你看到它的方式)

4. 4.

There is also another one off top of head cant remember it exactly, but its like a lookup with Mins and Sumproducts and a multiplacation in between, You may have come accross it by now.还有一个不记得了,但它就像一个查找 Mins 和 Sumproducts 以及两者之间的乘法,你现在可能已经遇到它了。 I was looking for that specific post where where I had detailed discussion/engagament a few year back, but I cant find it.我正在寻找几年前我进行过详细讨论/订婚的那个特定帖子,但我找不到它。 Here is similar:这里是类似的:

from Excel formula - last row dynamic range来自Excel 公式 - 最后一行动态范围

=MAX((1:1=LOOKUP(2,1/(1:1<>""),1:1))*(COLUMN(1:1)))

Only doesnt work as expected when 0's after you data.仅当数据后为 0 时才按预期工作。 You can get aroud that by wraping those 16384 type values with char(34) or similar.你可以通过用 char(34) 或类似的方法包装那些 16384 类型值来解决这个问题。

So, knowing all the above, I decided/wanted to make number 1, because of the limitations of the above approaches (and others not mentioned) with "0's in or after your data", and/or "blank/non-blank cells" issues were annoying to me, even if they too have their uses.因此,了解以上所有内容后,我决定/想要排在第 1 位,因为上述方法(以及其他未提及的方法)在“数据中或数据后为 0”和/或“空白/非空白单元格”的限制“问题对我来说很烦人,即使它们也有它们的用途。

So wanted a get/find last used cell whatever it is, however your data is arranged, and even when you don't even know it.所以想要一个获取/查找最后使用的单元格,不管它是什么,不管你的数据是如何排列的,即使你甚至不知道它。 Hence number 1.因此编号为 1。

This is how you can do it:您可以这样做:

=INDEX(2:2,COUNTA(2:2))
  • 2:2 means row 2 2:2 表示第 2 行
  • COUNTA returns the number of nonempty cells in a row COUNTA返回一行中非空单元格的数量
  • INDEX returns the value INDEX返回值

Note that the approach above assumes that all your cells up to the last one are nonblank.请注意,上述方法假定直到最后一个单元格为止的所有单元格都是非空白的。

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

相关问题 一个程序,它将在最后一行中找到具有最小值的列,并将其在第一行中的值分配给变量? [Excel VBA] - A program that will find the column with a minimum value in its last row and assign its value in the first row to a variable? [Excel VBA] 在Excel中查找具有特定值的列中最后一行的行号 - Finding the row number of last row in column with a specific value in excel Excel:如何查找列的第一行的值,具体取决于在同一列的另一行中查找给定数字的位置 - Excel: How to find the first row's value of a column depending on where to find a given number in another row of the same column C#-Excel:删除行,具体取决于第一列中的值 - C# - Excel: Delete Row, depending on value in first Column 查找连续具有特定值的第一个和最后一个条目 - finding the first and last entry with a certain value in a row 在动态行中查找最后一个值(Excel) - Finding the Last Value in a Dynamic Row (Excel) 在Excel中找到匹配行的最后一个值 - finding last value with matching row in excel Python-Excel:查找列中的第一个空行 - Python - Excel: Finding the first empty row in a column VBA在表列中查找具有值的最后一行 - VBA Finding Last Row with Value in Table Column 比较Excel中row的第一个和最后一个值 - Compare first and last value of row in Excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM