Richa
Richa

Reputation: 73

VBA Selection based on cell value

My code returns with an error. The result is as wished, but the error message is rather annoying. How can I get rid of this?

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


Run-time error '424': Object required

Upvotes: 0

Views: 54

Answers (1)

Mikku
Mikku

Reputation: 6664

Try:

Sub SELECTIE_VERZUIM()

    Dim Cval As Variant

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

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

End Sub

Also, you should avoid using Select in VBA

Upvotes: 1

Related Questions