根据单元格值选择VBA

时间:2019-08-28 10:25:38

标签: excel vba

我的代码返回错误。结果是所希望的,但是错误消息却很烦人。我该如何摆脱呢?

Sub SELECTIE_VERZUIM()

Dim Cval As Variant
Dim Rng1 As Range
Cval = Sheet4.Range("A16").Value
Set Rng1 = Sheet4.Range("D1:T" & Cval).Select

End Sub


  

运行时错误“ 424”:   所需对象

1 个答案:

答案 0 :(得分:1)

尝试:

Sub SELECTIE_VERZUIM()

    Dim Cval As Variant

    Cval = Sheet4.Range("A16").Value

    Sheet4.Range("D1:T" & Cval).Select

End Sub

此外,您应该避免在VBA中使用Select