简体   繁体   English

Excel宏可基于单元格值验证2列

[英]Excel Macro to validate 2 columns based on cell values

I am at initial stage in creating Macros. 我处于创建宏的初始阶段。 I know how to validate one column at a time, but not sure about validating a column reference to other column in the same row. 我知道如何一次验证一列,但不确定如何验证对同一行中另一列的引用。 Hope someone will help me with this! 希望有人能帮助我!

Scenario: validate 2 columns in a spreadsheet (debit and credit columns). 场景:验证电子表格中的2列(借方和贷方列)。

Condition: For every filled row, I should have one of the two column values as "0", highlight both the columns if non of the column value is "0". 条件:对于每个填充的行,我应该将两个列值之一设为“ 0”,如果两个列值都不为“ 0”,则突出显示两个列。

附件是样本数据

Don't use VBA, use the built-in Conditional Formatting. 不要使用VBA,请使用内置的条件格式。

Assuming those columns are A and B, let's say A2:A10 and the Credit is B2:B10 . 假设这些列是A和B,则假设A2:A10 ,而功劳为B2:B10

Go to Conditional Formatting, New Rule. 转到条件格式,新规则。

Select "Use a formula to determine ..." and type in =AND($A2<>0,$B2<>0,$A2<>"",$B2<>"") . 选择“使用公式确定...”,然后键入=AND($A2<>0,$B2<>0,$A2<>"",$B2<>"") Then click "Format" and Fill Red. 然后单击“格式”,然后填写红色。

Then click "Ok", "Ok" and change "Applies to" range to $A$2:$B$10 . 然后单击“确定”,“确定”,并将“适用于”范围更改为$A$2:$B$10

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM