vba 将 A 列中的每个单元格与 B 列和 C 列中的每个单元格进行比较

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15934180/
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-11 20:32:28  来源:igfitidea点击:

Compare each cell from column A with each cell from column B and colum C

excelexcel-vbavba

提问by Reynier

I've a Excel file with three columns. Cells in each columns are different ranges for example column A has 797340 cells, column B has 91617 cells and column C has 95891 cells. I need to compare each value in column A and look if this value is on column B or it's in column C and if the condition is TRUE then bold the cell or change the color to red. If there any way to achieve this using Excel formulas? Any help?

我有一个包含三列的 Excel 文件。每列中的单元格是不同的范围,例如 A 列有 797340 个单元格,B 列有 91617 个单元格,C 列有 95891 个单元格。我需要比较 A 列中的每个值,并查看该值是在 B 列上还是在 C 列中,如果条件为 TRUE,则将单元格加粗或将颜色更改为红色。如果有任何方法可以使用 Excel 公式实现这一点?有什么帮助吗?

回答by Santosh

You can use conditional formating. Kindly refer to below image. Its just a demo.

您可以使用条件格式。请参考下图。它只是一个演示。

Select Column A> Goto Conditional Formatting >> New Rules >> Use Formula to determine which cells to format

Enter the formula in >> Format values where formula is true >> select the format >> OK

选择A列>转到条件格式>>新规则>>使用公式来确定要设置格式的单元格

在 >> 格式值为 true 的地方输入公式 >> 选择格式 >> 确定

=OR( IF(ISNA(VLOOKUP(A1,B:B,2,0)),FALSE,TRUE),IF(ISNA(VLOOKUP(A1,C:C,3,0)),FALSE,TRUE))

enter image description here

在此处输入图片说明

回答by JAGAnalyst

Unless there is a reason you need to handle this with code, you can set conditional formatting within excel based on a formula.

除非有理由需要用代码处理这个问题,否则您可以根据公式在 excel 中设置条件格式。

For example, you can create a new conditional formatting rule based on a formula such as:

例如,您可以基于以下公式创建新的条件格式规则:

=IF(ISERROR(VLOOKUP([Cell in Column A],[Column B Range],1,FALSE)),"FALSE","TRUE")

This formula will return true when a matching value is found in column B. Then simply apply the same rule again for column C.

当在 B 列中找到匹配值时,此公式将返回 true。然后只需对 C 列再次应用相同的规则。

Apply this rule to the entire range of your column A cells, and set the conditional formatting to return bold and red when true.

将此规则应用于 A 列单元格的整个范围,并将条件格式设置为在 true 时返回粗体和红色。

Good luck!

祝你好运!

Example with ranges in one worksheet: Formula as applied is

一个工作表中的范围示例:应用的公式是

=IF(ISERROR(VLOOKUP($B3,$F:$F,1,FALSE)),"FALSE","TRUE")

Example

例子

回答by Young Bob

To make life easy use conditional formatting and apply your own custom rule.

为了让生活更轻松,请使用条件格式并应用您自己的自定义规则。

http://office.microsoft.com/en-gb/excel-help/quick-start-apply-conditional-formatting-HA010370614.aspx

http://office.microsoft.com/en-gb/excel-help/quick-start-apply-conditional-formatting-HA010370614.aspx