vba Excel 如果 A1=A2 那么 B1=B2 怎么办?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20116312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:33:26  来源:igfitidea点击:

Excel If A1=A2 then B1=B2 how to do that?

vbaexcel-vbaexcel

提问by Tanzil

A1 B1
A2 B2
A3 B3
A4 B4
A5 B5
A6 B6

IF A1=A2=A3=A4then insert content (text) of B1into B2=B3=B4

IF A1=A2=A3=A4然后插入内容(文本)B1B2=B3=B4

How to make such formula for excell??

如何为excel制作这样的公式?

Example

例子

If A1=Mango & B1=1, then All B cells which has Mango on left will be filled up with 1. Similarly if A9=Apple, B9=5, then All B cells which has Apple on left will be filled up with 5

如果 A1=Mango & B1=1,那么所有左边有 Mango 的 B 单元格都会被 1 填充。 同样如果 A9=Apple,B9=5,那么所有左边有 Apple 的 B 单元格都会被填充 5

回答by Oliver Matthews

If I am reading you right, then you want the contents of the cells BXonwards to be set to the value of B1if the value of AXis equal to A1

如果我没看错,那么您希望将单元格的内容BX设置为值,B1如果 的值AX等于A1

In this case, the formula is (for row 2)

在这种情况下,公式是(对于第 2 行)

=IF(A=A2,B,0)

This will set the cell to 0 if they are not equal - change this to whatever value you want it to actually be.

如果它们不相等,这会将单元格设置为 0 - 将其更改为您希望它实际为的任何值。

Note the use of $to lock which row is being referenced.

请注意使用$来锁定正在引用的行。

From your example, it looks more like you want to use a vlookup. This requires a second table of 'known' pairs - e.g.

从您的示例中,看起来更像是您想使用vlookup. 这需要第二个“已知”对表 - 例如

  C D
1 1 MANGO 
2 9 APPLE

Then in the actual data table you'd put (assuming you'd put the source data in columns C,D

然后在您放置的实际数据表中(假设您将源数据放在列 C、D

  A     B
1 Apple =VLOOKUP(A1,$C:$D,2,FALSE)
2 Thing =VLOOKUP(A2,$C:$D,2,FALSE)

etc

等等