简体   繁体   English

根据另一列中的单元格值验证一列中的单元格值

[英]Validate cell value in one column based on cell value in another column

I want to validate three columns in Excel. 我想验证Excel中的三列。

  1. If I give value in one column and remaining two columns leave it as empty then it should throw error for remaining two columns. 如果我在一列中提供值,而其余两列将其保留为空,则对于其余两列应抛出错误。
  2. If we leave three columns as empty then it should not throw any error 如果我们将三列留空,则不应引发任何错误

Here is my code: 这是我的代码:

rowToValidate = ActiveCell.Row

colToValidate = ActiveCell.Column + 1

Dim celAdd As String
celAdd = rowToValidate + colToValidate

Different ways to do this but here's one approach, assuming the columns are side-by-side. 做到这一点的方法不同,但这是一种方法,假设各列是并排的。 You can adjust the Offset as necessary. 您可以根据需要调整Offset

Sub Test()
    If Not IsEmpty(ActiveCell.Value) And _
           IsEmpty(ActiveCell.Offset(, 1).Value) And _
           IsEmpty(ActiveCell.Offset(, 2).Value) Then
        ' Do whatever you wanted to do
    End If
End Sub

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

相关问题 根据另一个列值过滤项目,结果在一个单元格中 - Filter items based on another column value with result in one cell 根据 Excel 中的另一个单元格值验证单元格 - Validate cell based on another cell value in Excel 根据另一列中的单元格值命名工作表 - Name worksheets based on cell value in another column 根据另一个单元格值更改列宽 - Change column width based on another cell value 有没有办法根据另一列中的一个单元格扫描整个列并提取相应列的值? - Is there a way to scan an entire column based on one cell in another column and pull out a value of the corresponding column? 如果第 7 列中的一个单元格等于另一个单元格中的值,则更改为另一个单元格中的值 - If a cell in Column 7 equals the value in another cell change to the value in another cell 列中的条件格式单元格基于它在另一列中的对应值 - Conditional format cell in column based on it corresponding value in another column 将单元格的最后一个值复制到另一列的单元格中 - copy last value of a cell into a cell of another column 如何根据另一列中的值替换单元格值以进行状态更新? - How to replace cell value based on a value in another column for status update? Excel-根据另一列中的值替换单元格值 - Excel - Replace cell value based on a value in another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM