英文:
How do I get the longest text of a row in some column in the middle of an Excel file? Formulas or VBA are okay
问题
I have an excel file in the column somewhere in the middle of which (yellow selected row for example) I need to find the longest text of that row, and do that for each row in that column.
I obviously get a circle reference if I simply select the whole row as the range, and what I tried with VBA making two ranges out of that gets over-complicated quickly, making me think there must be an easier way, potentially even using a formula.
I have to follow the following rules due to requirements for the file:
- I can only use that column (yellow)
- I don't know per se how long the row is going to go on, something I can easily check via VBA
- the leftmost column has to be excluded
Is there an easy way? Any ideas?
I tried simply selecting the row, obviously leads to a circle reference.
I've tried defining arrays via formula to include the two ranges, that didn't quite work out.
I've begun writing VBA code, but trying to combine two Ranges of that row, excluding a cell in-between is where it falls flat.
英文:
I have an excel file in the column somewhere in the middle of which (yellow selected row for example) I need to find the longest text of that row, and do that for each row in that column.
I obviously get a circle reference if I simply select the whole row as the range, and what I tried with VBA making two ranges out of that gets over-complicated quickly, making me think there must be an easier way, potentially even using a formula.
I have to follow the following rules due to requirements for the file:
- I can only use that column (yellow)
- I don't know per se how long the row is going to go on, something I can easily check via VBA
- the leftmost column has to be excluded
Is there an easy way? Any ideas?
I tried simply selecting the row, obviously leads to a circle reference.
I've tried defining arrays via formula to include the two ranges, that didn't quite work out.
I've begun writing VBA code, but trying to combine two Ranges of that row, excluding a cell in-between is where it falls flat.
答案1
得分: 3
这是一个选项:
单元格 E2
中的公式:
=BYROW(2:7,LAMBDA(x,LET(y,DROP(FILTER(x,COLUMN(x)<>COLUMN()),,1),@SORTBY(y,LEN(y),-1))))
英文:
Here is one option:
Formula in E2
:
=BYROW(2:7,LAMBDA(x,LET(y,DROP(FILTER(x,COLUMN(x)<>COLUMN()),,1),@SORTBY(y,LEN(y),-1))))
答案2
得分: 0
"The "brute force" technique is to access an additional dimension by inserting a new Sheet.<br> In that new Sheet2, in B2, have =LEN(Sheet1!B2)
and drag across and down.<br> That has given you an easier point from which to find what it is that you want.<br> Even if the data covered every single cell in Sheet1, and so in Sheet2, you could add Sheet3, and in B1 put E.g. =MAX(Sheet2!B:B)
and in B2 =IF(Sheet2!B2=Sheet3!$B$1,ROW(),"")
<br> Then on Sheet4, in B2, =OFFSET(Sheet1!B1,SUM(Sheet3!B2:B1048576)-1,0)
<br> In practice you probably do have some spare rows/columns (can you add a row at the top of the source sheet?) so you can probably put the answer on Sheet3.<br> The key is to separate the different steps: finding the length; finding the largest length, finding in which cell that occurs, and accessing the value in that cell."
英文:
The "brute force" technique is to access an additional dimension by inserting a new Sheet.<br>
In that new Sheet2, in B2, have =LEN(Sheet1!B2)
and drag across and down.<br>
That has given you an easier point from which to find what it is that you want.<br>
Even if the data covered every single cell in Sheet1, and so in Sheet2, you could add Sheet3, and in B1 put E.g. =MAX(Sheet2!B:B)
and in B2 =IF(Sheet2!B2=Sheet3!$B$1,ROW(),"")
<br>
Then on Sheet4, in B2, =OFFSET(Sheet1!B1,SUM(Sheet3!B2:B1048576)-1,0)
<br>
In practice you probably do have some spare rows/columns (can you add a row at the top of the source sheet?) so you can probably put the answer on Sheet3.<br>
The key is to separate the different steps: finding the length; finding the largest length, finding in which cell that occurs, and accessing the value in that cell.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论