2
  If Target.Column = 6 Then
  End If

如果 Column 为 6 或 8 或 10,我希望执行 If 代码。我应该如何修改上面的代码

4

2 回答 2

2

你可以使用 case 语句

CASE 语句 (VBA)

见章节

You can also comma delimit values. For example:


Select Case LNumber
    Case 1, 2
       LRegionName = "North"
    Case 3, 4, 5
       LRegionName = "South"
    Case 6
       LRegionName = "East"
    Case 7, 11
       LRegionName = "West"
 End Select
于 2012-08-28T11:31:23.473 回答
1

这就是你问的更具体的问题:

If Target.Column = 6 OR Target.Column = 8 OR Target.Column = 10 Then
'Code for if a match is found.
else
'Code for when a match isn't found.
End If

或如 asstander 所示:

Select Case Target.Column
Case 6, 8, 10
'Code for if a match is found.
Case Else
'Code for when a match isn't found.
End Select

甚至另一种方式:

With Target
If .Column = 6 Or .Column = 8 OR .Column = 10 then
'Code for if a match is found.
else
'Code for when a match isn't found.
End If
End with
于 2012-08-28T12:50:01.650 回答