将范围设置为相对于活动单元格的单个单元格

时间:2013-09-14 18:12:33

标签: vba range offset relative

当我尝试将范围定义为相对于当前单元格的单个单元格时,我收到范围失败的错误:

If target.Cells.Column = 2 Then
    If target.Cells.Row > 3 Then
        If target.Cells.Count = 1 Then
        Range(ActiveCell.Offset(0, 1)).Select
        End If
    End If
End If

我知道我可以在当前单元格中创建范围,然后在之后进行偏移但我只想定义范围

1 个答案:

答案 0 :(得分:0)

Dim c As Range

If target.Cells.Count = 1 Then
    If target.Row > 3 and target.Column = 2 Then
        Set c = target.Offset(0, 1)
        'do something with c
    End If
End If