您好我在 VBA 相当新。我正在处理一个超过 10,000 行的大型电子表格。我想要完成的是:
这就是我下面的内容,它在下面不起作用,我遇到了错误。任何帮助表示赞赏。
Sub find_mismatch()
Dim c As Range
Dim string1 As String
Dim string2 As String
string1 = "Apple"
string2 = "Orange"
For Each c In Range("E1:E10138")
If c.Value = 1 Then
If ActiveCell.Offset(-1, 0).Value = string1 Or string2 Then
ActiveCell.Offset(2, 0).Value = "True"
End If
End If
Next
End Sub
最佳答案
多个 if 条件总是必须完整地写出来,即使感觉像是在重复自己。
改变这个:
If ActiveCell.Offset(-1, 0).Value = string1 Or string2 Then
ActiveCell.Offset(2, 0).Value = "True"
End If
对此:
If c.Offset(0, -1).Value = string1 Or c.Offset(0, -1).Value = string2 Then
c.Offset(0, 2).Value = "True"
End If
编辑:刚刚意识到行和列也被颠倒了。偏移量的语法是 Offset(Rows,Columns)。所以要向左走,您将负数放在第二个参数而不是第一个参数中。
关于vba - 如果多个条件匹配,则返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33551149/