将多个范围添加到一个参数中

问题描述 投票:0回答:1

我有这个工作代码:

If Not Intersect(ActiveCell, Range("D6:D15")) Is Nothing Then
    MsgBox "busses"
Else
    MsgBox "Select Only Cells With Asset ID", vbCritical
    Exit Sub
End If

我想在该行中添加更多范围,如下所示:

If Not Intersect(ActiveCell, Range("D6:D15") Or ("G6:G15") Or ("J6:J15")) Is Nothing Then
    MsgBox "busses"
Else
    MsgBox "Select Only Cells With Asset ID", vbCritical
    Exit Sub
End If
excel vba
1个回答
0
投票

您可以定义由不同单元格组成的范围:

If Not Intersect(ActiveCell, Range("D6:D15,G6:G15,J6:J15")) Is Nothing Then
    MsgBox "busses"
Else
    MsgBox "Select Only Cells With Asset ID", vbCritical
    Exit Sub
End If
© www.soinside.com 2019 - 2024. All rights reserved.