Excel语句逻辑概念
晚上好!
我试图做出一些擅长的声明有如下的外观:
我想要做的是:
if(A1=1 and B1=0) output would be A1=1 and B2=0 if(A1=0 and B1=1) output would be A1=0 and B2=1 if(A1=0 and B2=0) output is an error. if(A1=1 and B2=1) output is an error. if(A1="-"and B2="-") output would be A1="-" and B2="-".
A和B的所有单元格都一样。有什么build议吗?
您将需要发布以下代码,当列A或B中的任何内容更改为图表对象时,将激活您的macros:
Private Sub Worksheet_Change(ByVal Target As Range) Dim x As Long If Not Intersect(Target, Columns("A:B")) Is Nothing Then Call Evaluatecells End If End Sub
下面的代码评估你的单元格的标准,将进入模块:
Sub Evaluatecells() lastrow = ActiveSheet.UsedRange.Rows.Count For x = 2 To lastrow If Cells(x, 1).Value = 0 And Cells(x, 2).Value = 0 Then MsgBox ("Error - Values in A1 and B1 cannot be both 0.") Exit For ElseIf Cells(x, 1).Value = 1 And Cells(x, 2).Value = 1 Then MsgBox ("Error - Values in A1 and B1 cannot be both 1.") Exit For End If Next x End Sub
如果您有任何问题,请告诉我。