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
Excel If A1=A2 then B1=B2 how to do that?
提问by Tanzil
A1 B1
A2 B2
A3 B3
A4 B4
A5 B5
A6 B6
IF A1=A2=A3=A4
then insert content (text) of B1
into B2=B3=B4
IF A1=A2=A3=A4
然后插入内容(文本)B1
到B2=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 BX
onwards to be set to the value of B1
if the value of AX
is 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
等等