Excel - 在单元格匹配之后,在标题之间返回值 [英] Excel - Return value, after cell has been matched, between headers

查看:208
本文介绍了Excel - 在单元格匹配之后,在标题之间返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这里我再一次请求这个伟大社区的帮助。
我希望我可以跟你做的有一天一样。



图片中的第4列(D)是预期的输出。



这是我如何解决问题:




  • 如果一个数字是负数或/有一个A(A行中的数字总是为负数);




    • 使用MATCH来检查是否有记者)数字范围(在标题之间);


    • 如果有一个MATCH输出,匹配的F的ID(第1列)的值,然后输出匹配的A的ID



  • 如果没有,放置一个0。




问题是:




  • 需要循环,因为负值可以在正值之后;


  • 搜索必须包含在标题。




我尝试从提示和代码修改并创建自己的解决方案o f我的其他问题,但没有成功..



非常感谢!

 名称。添加i,= $ A $ 1:$ A $ 12:_ 
Names.Addv,= $ B $ 1:$ B $ 12:_
Names.Addm ,= $ D $ 1:$ D $ 12:_
Names.Addh,[IF({1},LOOKUP(ROW(i))ROW(i)/(v = INDEX 1))))] _ _
Names.Addl,[IF({1},LOOKUP(ROW(i),ROW(i)/(v = INDEX(v,1))),FREQUENCY (-ROW(i),IF(v = INDEX(v,1), - ROW(i),0)) - 1))]:_
[m] = [IF(COUNTIF(OFFSET ,=),CONCATENATE(=,ADDRESS(ROW(i),COLUMN(i),4),&AND& INDEX ,ADDRESS(H + 1,列(I)), :,ADDRESS(H + L,COLUMN(I)), MATCH( - ,ADDRESS(ROW(v)中,COLUMN(v),4) ,,,ADDRESS(h + 1,COLUMN(v)),:,ADDRESS(h + 1,COLUMN(v)),,0))),)]:_
名称(h)删除:_
名称(l)。删除

问题的示例数据的输出是:

  D5 = A5&AND & INDEX($ A $ 2:$ A $ 6,MATCH(-B5,$ B $ 2:$ B $ 6,0))
D11 = A11&AND& INDEX($ A $ 11:$ A $ 12,MATCH(-B11,$ B $ 11:$ B $ 12,0))

注意:此方法使用命名数组来存储标题位置 h 和段长度 l 的中间结果,当范围名称 i (id), v (value)和<$ c $时,需要3-4秒左右c> m (match)扩展为40,000行。一个更简单的公式是可能的,但填写大数据集将是非常低效的。


Here I am once again, asking for help on this great community. I hope I can retribute as much as you did someday.

The 4th column (D) in the picture is the expected output.

This is how I put the problem:

  • If a number is negative / or has an A (number in the A row is always negative);

    • Use MATCH to check if there is a correspondent (positive) number in the range (between headers);

    • If there is a MATCH output the value of the ID (1st column) of the F that has been matched, and then, output the ID of the A that has been matched

  • If not, do nothing or place a 0.

The problems are:

  • It needs to loop, because the negative value can come after the positive one;

  • The search must be contained between headers.

I've tried to modify and create my own solutions from the tips and codes of the other questions I've placed, but with no success..

Thank you so much!

解决方案

Try pasting this into the immediate window of the VBE and hitting enter:

Names.Add "i", "=$A$1:$A$12": _
Names.Add "v", "=$B$1:$B$12": _
Names.Add "m", "=$D$1:$D$12": _
Names.Add "h", [IF({1},LOOKUP(ROW(i),ROW(i)/(v=INDEX(v,1))))]: _
Names.Add "l", [IF({1},LOOKUP(ROW(i),ROW(i)/(v=INDEX(v,1)),FREQUENCY(-ROW(i),IF(v=INDEX(v,1),-ROW(i),0))-1))]: _
[m]=[IF(COUNTIF(OFFSET(v,h,,l),"=-"&v),CONCATENATE("=",ADDRESS(ROW(i),COLUMN(i),4),"&"" AND ""&INDEX(",ADDRESS(h+1,COLUMN(i)),":",ADDRESS(h+l,COLUMN(i)),",MATCH(-",ADDRESS(ROW(v),COLUMN(v),4),",",ADDRESS(h+1,COLUMN(v)),":",ADDRESS(h+l,COLUMN(v)),",0))"),"")]: _
Names("h").Delete: _
Names("l").Delete

The output for the example data in the question is:

D5  =A5&" AND "&INDEX($A$2:$A$6,MATCH(-B5,$B$2:$B$6,0))
D11 =A11&" AND "&INDEX($A$11:$A$12,MATCH(-B11,$B$11:$B$12,0))

Note: This method uses named arrays to store intermediate results for header positions h and section lengths l and takes around 3-4 secs when the range names i (id), v (value) and m (match) are extended to 40,000 rows. A simpler formula for this is possible but it would be very inefficient to fill down on large data sets.

这篇关于Excel - 在单元格匹配之后,在标题之间返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆